简体   繁体   English

如何从JavaScript中的char中获取make代码?

[英]How to get make code from char in JavaScript?

I am working on v86 emulator for node from this library . 我正在为此库中的节点使用v86模拟器。 I need to send some keyboard inputs, but I first need convert it to make code . 我需要发送一些键盘输入,但首先需要将其转换为代码 Is there any JavaScript function to do it? 有没有执行此功能的JavaScript函数?

a => 0x1E
b => 0x30
c => 0x2E

Here is the table of that codes : 这是该代码表

Key      Make  Break        Key    Make  Break

    Backspace     0E    8E          F1  3B    BB
    Caps Lock     3A    BA          F2  3C    BC
    Enter         1C    9C          F3  3D    BD
    Esc       01    81          F4  3E    BE
    Left Alt      38    B8          F7  41    C1
    Left Ctrl     1D    9D          F5  3F    BF
    Left Shift    2A    AA          F6  40    C0
    Num Lock      45    C5          F8  42    C2
    Right Shift   36    B6          F9  43    C3
    Scroll Lock   46    C6          F10 44    C4
    Space         39    B9          F11 57    D7
    Sys Req (AT)  54    D4          F12 58    D8
    Tab       0F    8F

            Keypad Keys            Make   Break

            Keypad 0  (Ins)     52  D2
            Keypad 1  (End)         4F  CF
            Keypad 2  (Down arrow)  50  D0
            Keypad 3  (PgDn)        51  D1
            Keypad 4  (Left arrow)  4B  CB
            Keypad 5            4C  CC
            Keypad 6  (Right arrow) 4D  CD
            Keypad 7  (Home)        47  C7
            Keypad 8  (Up arrow)    48  C8
            Keypad 9  (PgUp)        49  C9
            Keypad .  (Del)         53  D3
            Keypad *  (PrtSc)       37  B7
            Keypad -            4A  CA
            Keypad +            4E  CE

           Key    Make  Break          Key    Make  Break

        A      1E    9E         N      31    B1
        B      30    B0         O      18    98
        C      2E    AE         P      19    99
        D      20    A0         Q      10    90
        E      12    92         R      13    93
        F      21    A1         S      1F    9F
        G      22    A2         T      14    94
        H      23    A3         U      16    96
        I      17    97         V      2F    AF
        J      24    A4         W      11    91
        K      25    A5         X      2D    AD
        L      26    A6         Y      15    95
        M      32    B2         Z      2C    AC

           Key    Make  Break          Key    Make  Break

        1      02    82         -      0C    8C
        2      03    83         =      0D    8D
        3      04    84         [      1A    9A
        4      05    85         ]      1B    9B
        5      06    86         ;      27    A7
        6      07    87         '      28    A8
        7      08    88         `      29    A9
        8      09    89         \      2B    AB
        9      0A    8A         ,      33    B3
        0      0B    8B         .      34    B4
                        /      35    B5

And yes. 是的。 I can rewrite it to JavaScript, but there is also some other keyboard keys and it will take long time to do it, so this is reason why I am asking this. 我可以将其重写为JavaScript,但是还有其他一些键盘键,并且需要很长时间才能完成,所以这就是我问这个的原因。

All of the answers and comments here completely miss the point. 这里的所有答案和评论都完全忽略了重点。 There is no Unicode code for Right Shift press and there is no Unicode code for Right Shift release. 右移印刷没有Unicode代码,右移印刷没有Unicode代码。 Likewise, you cannot make a string out of a Right Shift press and Print Screen release to parse it and print the codes. 同样,您不能通过按Shift键并按下Print Screen释放键来解析和打印代码。 How could you even possibly put a Right Shift release in a string? 您甚至怎么可能将Right Shift版本放入字符串中? Apparently some people here have bigger imagination than me. 显然,这里有些人比我有更大的想象力。

The make and break codes have nothing to do with characters that can be printed on the screen or stored in strings. 接通和断开代码与可以在屏幕上打印或存储在字符串中的字符无关。 Those are codes that the keyboard sends to signal key presses and releases. 这些是键盘发送来指示按键和释放的代码。 Then the operating system can translate those codes into characters but not directly. 然后,操作系统可以将这些代码转换为字符,但不能直接转换为字符。 For example if a shift was pressed but was not released and then a code that corresponds to a press of a letter Q on a QWERTY keyboard is detected then the operating system may interpret it as an uppercase Q (unless the caps lock was on) and if it doesn't detect a release of the Q letter it may also start automatically repeating it until it detects the release of the letter Q. But the same code that is sent for the letter Q on a QWERTY keyboard is sent for the letter A on an AZERTY keyboard. 例如,如果按下了一个档但没有释放该档,然后检测到与按下QWERTY键盘上的字母Q对应的代码,则操作系统可以将其解释为大写Q(除非大写锁定处于打开状态),并且如果它没有检测到Q字母的释放,它也可能会开始自动重复它,直到它检测到字母Q的释放。但是,为Q字母发送的是在QWERTY键盘上为字母Q发送的相同代码。在AZERTY键盘上。 It doesn't matter what is printed on the key, the physical location and electrical connection of the key is what matters. 密钥上印有什么无关紧要,密钥的物理位置和电气连接至关重要。

Now, there are some modules on npm that you may take a look at: 现在,您可以在npm上查看一些模块:

but I doubt you will actually find something useful because yu normally don't work on such a low level of keyboard hardware with JavaScript or Node. 但我怀疑您实际上会发现有用的东西,因为您通常无法在使用JavaScript或Node的如此低级别的键盘硬件上工作。

If you don't find anything useful on npm and you end up rewriting the table that you included in JavaScript then consider publishing it on npm so others could use it. 如果在npm上找不到任何有用的东西,而最终重写了JavaScript中包含的表,则可以考虑在npm上发布它,以便其他人可以使用它。

Update 更新

I just found this module: 我刚刚找到了这个模块:

It seems to include some of the codes that you need. 它似乎包括您需要的一些代码。 You may be able to get it from its source code. 您可能可以从其源代码中获取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM