How to capture the arrow keys in node.js

前端 未结 5 1174
南旧
南旧 2020-12-29 05:57

What is the utf8 code for all four arrow keys (up down left right)?

I am learning node.js and I am trying to detect whenever these keys are being pressed.

He

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 06:29

    Assuming you mean the key codes:

    Up: 38
    Down: 40
    Left: 37
    Right: 39
    

    http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

    To capture them in JavaScript:

    if (key.which == 39) {
        // go right!
    }
    

提交回复
热议问题