<script>
var flag = 0;
var t;
function openFlag () {
t = setTimeout(function(){flag = 1; dosomething();}, 1000);
}
function closeFlag() {
clearTimeout(t);
flag = 0;
}
function dosomething() {
if (flag) {
// do something
alert('aaa');
}
}
</script> <input type="text" onkeydown="openFlag()" onkeyup="closeFlag()" />