views:

595

answers:

1

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.

+2  A: 

Simple sendKeys example, only works in IE. You will have to enable ActiveX as it needs to instantiate a WScript Shell.

<script>
function pageSetup()
{
    var shell;
    shell = new ActiveXObject("WScript.Shell");
    shell.SendKeys("%fu");
}
</script>

<div onclick="pageSetup();" style="cursor:pointer;">Open Page Setup</div>
bignic
This does seem to be a good starting point, but since it leaves the javascript realm and there would be race conditions. I think the way we wnated to do this may not be doable at this time.
Jason Pyeron