javascript hotkeys

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
what i'm trying to do is capture certain types of key events with javascript. it's akin to using the text editor for the forums here, if you press ctrl+b then the text is bold, but the bookmarks don't come up.

in my application i can get the event captured, the equivalent to making the text bold, but the bookmarks still come up.

so basically i'm looking to make some hotkeys. any suggestions are appreciated

Code:
document.onkeydown = KeyCheck;//ctrlChk;
document.onkeyup = ctrlChk;//KeyCheck;

function ctrlChk(e)
{
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    
    if(KeyID == 17)
    {
        ctrl = false;
    }
}
function KeyCheck(e)
{
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    if(KeyID == 17)
        ctrl = true;
        if(window.event)
    {
        window.event.keyCode = 555;
        alert(event.keyCode);
    }
    else
    {
        window.e.keyCode = 555;
        alert(e.keyCode);
    }
    switch(KeyID)
    {
        /*case 17: // 'ctrl' - modifier key
            ctrl = true;
            break;*/
        case 19: //'pause' - pause/resume tourney
            tourneyGoing = !tourneyGoing;
            break;
        case 27: // 'esc' - remove '-'
            Escape();
            break;
        case 109: // '-' - wait for key for removal
            keypressMinus();
            break;
        default:
            break;
    }
    if(ctrl)
    {
        switch(KeyID)
        {
--snip--
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Why don't you use Event.ctrlKey to check the state of the control key when a key is pressed?

But anyway, I believe that if you have the function return false, then it'll stop the browser hotkey from executing since onkeypress="return false;" seems to accomplish this.
 

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
thanks a ton, return false worked like a charm

and i'll have to give the event.ctrlkey a shot, it may make my life a bit easier.

edit:
I switched to using event.ctrlkey, which is working much better than my previous method.
 
Last edited:
Top