Post by [dmsuperman] on Feb 5, 2007 6:40:44 GMT
<script type='text/javascript'>
var keyArray = new Array();
keyArray["shift"] = keyArray["alt"] = keyArray["ctrl"] = keyArray["key"] = "";
var hotKeys = new Array();
function waitForKeys(e){
var chars1_32 = new Array("NULL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "Backspace", "Horizontal Tab", "Line Feed", "Vertical Tab", "New Page", "Carriage Return", "Shift Out", "Shift In", "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SNY", "ETB", "Cancel", "EM", "SUB", "Escape", "File Separator", "Group Separator", "Record Separator", "Unit Separator", "Space");
shiftPressed = false;
altPressed = false;
ctrlPressed = false;
var unicode=e.charCode? e.charCode : e.keyCode
var evt = navigator.appName=="Netscape" ? e:event;
shiftPressed=evt.shiftKey;
altPressed =evt.altKey;
ctrlPressed =evt.ctrlKey;
if(unicode<=32){
sstring = chars1_32[unicode];
}else if(unicode==127){
sstring = "Delete";
}else{
sstring = String.fromCharCode(unicode);
}
keyArray['shift'] = shiftPressed;
keyArray['ctrl'] = ctrlPressed;
keyArray['alt'] = altPressed;
keyArray['key'] = sstring;
init_keypress();
}
function init_keypress(){
keyPressed = "";
if(keyArray['ctrl']){
keyPressed += "1";
}else{
keyPressed += "0";
}
if(keyArray['shift']){
keyPressed += "1";
}else{
keyPressed += "0";
}
if(keyArray['alt']){
keyPressed += "1";
}else{
keyPressed += "0";
}
keyPressed += keyArray["key"];
if(hotKeys[keyPressed.toUpperCase()]!=""){
eval(hotKeys[keyPressed.toUpperCase()]);
}
if(hotKeys[keyPressed.toLowerCase()]!=""){
eval(hotKeys[keyPressed.toLowerCase()]);
}
}
hotKeys['100f'] = "CtrlF();";
hotKeys['011g'] = "ShiftAltG();";
hotKeys['100backspace'] = "backSpace();";
function CtrlF(){
alert("Ctrl + F Activated");
}
function ShiftAltG(){
alert("Shift + Alt + G Activated");
}
function backSpace(){
alert("Backspace event activated");
}
</script>
And set this in your body
<body onKeyPress="waitForKeys(event);">
Basically you set your hotkeys in the format of hotKeys['CTRL-SHIFT-ALT-KEY'] = "js to execute on keypress";
If you want the button to be activated, make it a 1, else make it 0.
Example, for Shift + Alt + G, it would be hotKeys['011G'] = "execute();";
Note that the hotkeys themselves must be all the same case (carriage return or CARRIAGE RETURN, not mixed case) for this to work. Not tested in IE, though it should work in that too. Included some examples in the code.