Binding arrow keys in JS/jQuery

后端 未结 16 2110
春和景丽
春和景丽 2020-11-22 12:25

How do I go about binding a function to left and right arrow keys in Javascript and/or jQuery? I looked at the js-hotkey plugin for jQuery (wraps the built-in bind function

16条回答
  •  一生所求
    2020-11-22 13:04

    You can use KeyboardJS. I wrote the library for tasks just like this.

    KeyboardJS.on('up', function() { console.log('up'); });
    KeyboardJS.on('down', function() { console.log('down'); });
    KeyboardJS.on('left', function() { console.log('right'); });
    KeyboardJS.on('right', function() { console.log('left'); });
    

    Checkout the library here => http://robertwhurst.github.com/KeyboardJS/

提交回复
热议问题