Add hotkeys to the web application

28 / Sep / 2009 by Amit Jain 0 comments

Let us have a look at the simple javascript code, that can be used to add hotkeys to our web application. I tried using jquery hotkeys plugin and two more plugins, but they didn’t work for me.

So I ended up handling the keydown event of my own.

var isAlt = false;
document.onkeyup = function(e) {
    if (e.which == 18) //18 is the keycode for 'Alt'
	isAlt = false;
}
document.onkeydown = function(e) {
    if (e.which == 18)
	 isAlt = true;
    else if (e.which == 69 && isAlt == true) { //69 is the keycode for 'e'
        function1(); 	 // executed when alt+e is pressed
        return false;
    } else if (e.which == 71 && isAlt == true) {
        function2(); 	 // executed when alt+g is pressed
        return false;
    }
    ...
}

Hope this helped.

Cheers!
~~Amit Jain~~
amit@intelligrape.com
IntelliGrape Softwares

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *