There are a few things you can do to achieve this. To clarify, you would like to be able to use the keyboard combo Ctrl + ; to allow the next keydown to trigger a piece of code? If this is what you are looking for, you could do something like this: (in jQuery)
// For getting the function corresponding to the key
function getPosition(arrayName,arrayItem)
{
for(var i=0;i<arrayName.length;i++){
if(arrayName[i]==arrayItem)
return i;
}
}
// Written By Ben Bales
var ctrlDown = false; // Tells if the cotrol button is currently down
var semicolonDown = false; // Tells if the semicolon button is down
var allowShortcut = false; // Allows the key following ctrl+; to run a function
var keyTimeout = 800; // Allows the following keystroke within this amount of milliseconds after ctrl+;
// reset allowShortcut
function disableShortcut()
{
allowShortcut = false;
console.log("dead");
}
$(document).keydown(function(e){
if(e.keyCode == 17) ctrlDown = true;
if(e.keyCode == 186 || e.keyCode == 59) semicolonDown = true;
//console.log("Semicolon: "+semicolonDown);
//console.log("Ctrl: "+ctrlDown);
// If both keys are down, allow a following key to do something
if(allowShortcut == true)
{
var key = e.keyCode;
//alert(key);
var actionPos = getPosition(keyArray,key);
actionArray[actionPos]();
allowShortcut = false;
}
if(ctrlDown == true && semicolonDown == true)
{
allowShortcut = true;
// after a certian amount of time dont allow the following key to do something
setTimeout(disableShortcut,keyTimeout);
}
});
$(document).keyup(function(e){
if(e.keyCode == 17) ctrlDown = false;
if(e.keyCode == 186 || e.keyCode == 59) semicolonDown = false;
});
// You may want to put your shortcuts in arrays with corresponding keyCodes like so:
var actionArray = new Array(doSomething,doSomethingelse);
var keyArray = new Array(65,66);
// sample actions
function doSomething()
{
alert("did something");
}
function doSomethingelse()
{
alert("did something else");
}
I just made this quickly and haven't tested it but hopefully you will understand what it is trying to do. But then again it's only a 15 year olds solution. If you set it up in an html template and try it out, try Ctrl + ; and then hit the A or B key to run their corresponding functions.
Let me know if you need any more help!