Multiple Key Detection in Javascript

I'm working on a way to make keyboard shortcuts. Initially I had done this:

function clicking(e) {  

    var code;

    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    var character = String.fromCharCode(code);

        if(character == 'X' && e.ctrlKey) {
            window.location = 'http://www.example.org/';            
        } 

}

Where the user would press Ctrl and X to redirect, or perhaps Ctrl + Alt + X. This works fine on windows of course, but on a Mac I'm having some problems. This was the simplest solution and I didn't want to overcomplicate it. On top of that my brain isn't functioning perfectly today, and I was wondering if there was any way around this on a Mac.

I want to keep the user experience the same throughout platforms.


Have you looked at using a plugin?

http://code.google.com/p/js-hotkeys/

链接地址: http://www.djcxy.com/p/54020.html

上一篇: Intellij快捷方式将代码转换为大写还是小写?

下一篇: Javascript中的多重键检测