Binding arrow keys in JS/jQuery

后端 未结 16 2117
春和景丽
春和景丽 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:22

    A robust Javascript library for capturing keyboard input and key combinations entered. It has no dependencies.

    http://jaywcjlove.github.io/hotkeys/

    hotkeys('right,left,up,down', function(e, handler){
        switch(handler.key){
            case "right":console.log('right');break
            case "left":console.log('left');break
            case "up":console.log('up');break
            case "down":console.log('down');break
        }
    });
    

提交回复
热议问题