I have a function which starts to gobble up keys after a hot key is pressed and fires off an AJAX process at the end of a sequence (barcode scan).
The issue is what happens if the user accidentally presses the hot key?
My paper napkin solution was:
on hotkey: if(okay(true)) {buffer=""; ts=now(); consumekey();}
on EOTkey: if(okay(false)) {AJAX(buffer); consumekey();}
on datakey: if(okay(false)) {appendbuffer(key); consumekey();}
on otherkey: dumpbuffer();
var status=false;
var ts=0;
var buffer="";
function okay(bool state)
{
if (state && !status) || (!state && status && !timeout(ts) ) return true;
dumpbuffer();
}
function dumpbuffer()
{
mybuffer=buffer;
buffer="";
ts=0;
status=false;
sendkeys(mybuffer);
}
So how do we write sendkeys in Javascript? (BTW this can be IE specific). The current implimentation uses jQuery, but our code does not have any content for the sendkeys function.