Monday, 29 May 2017

How to get make code from char in JavaScript?

I am working on v86 emulator for node from this library. I need to send some keyboard inputs, but I first need convert it to make code. Is there any JavaScript function to do it?

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.



via Samuel Tulach

No comments:

Post a Comment