Skip to content

Instantly share code, notes, and snippets.

@DJm00n
Last active October 28, 2023 16:11
Show Gist options
  • Save DJm00n/97db43f4b5e9a1ff11564fe828e03381 to your computer and use it in GitHub Desktop.
Save DJm00n/97db43f4b5e9a1ff11564fe828e03381 to your computer and use it in GitHub Desktop.
Make 1 Scancode to HID usage
static uint8_t Win32ScanCodeToHIDUsage(uint16_t scanCode)
{
uint8_t index = (scanCode & 0xff) < 0x80 ? (scanCode & 0xff) : 0x00;
if ((scanCode & 0xff00) != 0)
{
if ((scanCode & 0xff00) == 0xe000)
index |= 0x80;
else
index = 0;
}
// 256 bytes
static const uint8_t scan2usage[] =
{
0x00, 0x29, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x2d, 0x2e, 0x2a, 0x2b,
0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c, 0x12, 0x13, 0x2f, 0x30, 0x28, 0xe0, 0x04, 0x16,
0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x0f, 0x33, 0x34, 0x35, 0xe1, 0x31, 0x1d, 0x1b, 0x06, 0x19,
0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0xe5, 0x55, 0xe2, 0x2c, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e,
0x3f, 0x40, 0x41, 0x42, 0x43, 0x53, 0x47, 0x5f, 0x60, 0x61, 0x56, 0x5c, 0x5d, 0x5e, 0x57, 0x59,
0x5a, 0x5b, 0x62, 0x63, 0x00, 0x00, 0x64, 0x44, 0x45, 0x67, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x00,
0x88, 0x91, 0x90, 0x87, 0x00, 0x00, 0x73, 0x93, 0x92, 0x8a, 0x00, 0x8b, 0x00, 0x89, 0x85, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0xe4, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x46, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x4a, 0x52, 0x4b, 0x00, 0x50, 0x00, 0x4f, 0x00, 0x4d,
0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0x66, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
return scan2usage[index];
}
static uint16_t HIDUsageToScanCode(uint8_t usage)
{
uint8_t index = usage;
// 256 bytes
static const uint8_t usage2scan[] =
{
0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x2e, 0x20, 0x12, 0x21, 0x22, 0x23, 0x17, 0x24, 0x25, 0x26,
0x32, 0x31, 0x18, 0x19, 0x10, 0x13, 0x1f, 0x14, 0x16, 0x2f, 0x11, 0x2d, 0x15, 0x2c, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x1c, 0x01, 0x0e, 0x0f, 0x39, 0x0c, 0x0d, 0x1a,
0x1b, 0x2b, 0x2b, 0x27, 0x28, 0x29, 0x33, 0x34, 0x35, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
0x41, 0x42, 0x43, 0x44, 0x57, 0x58, 0xb7, 0x46, 0xc5, 0xd2, 0xc7, 0xc9, 0xd3, 0xcf, 0xd1, 0xcd,
0xcb, 0xd0, 0xc8, 0x45, 0xb5, 0x37, 0x4a, 0x4e, 0x9c, 0x4f, 0x50, 0x51, 0x4b, 0x4c, 0x4d, 0x47,
0x48, 0x49, 0x52, 0x53, 0x56, 0xdd, 0xde, 0x59, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b,
0x6c, 0x6d, 0x6e, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x73, 0x70, 0x7d, 0x79, 0x7b, 0x5c, 0x00, 0x00, 0x00,
0x72, 0x71, 0x78, 0x77, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1d, 0x2a, 0x38, 0xdb, 0x9d, 0x36, 0xb8, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
return ((usage2scan[index] & 0x80) ? 0xe000 : 0) | (usage2scan[index] & 0x7f);
}
0x0001 0x0029
0x0002 0x001e
0x0003 0x001f
0x0004 0x0020
0x0005 0x0021
0x0006 0x0022
0x0007 0x0023
0x0008 0x0024
0x0009 0x0025
0x000a 0x0026
0x000b 0x0027
0x000c 0x002d
0x000d 0x002e
0x000e 0x002a
0x000f 0x002b
0x0010 0x0014
0x0011 0x001a
0x0012 0x0008
0x0013 0x0015
0x0014 0x0017
0x0015 0x001c
0x0016 0x0018
0x0017 0x000c
0x0018 0x0012
0x0019 0x0013
0x001a 0x002f
0x001b 0x0030
0x001c 0x0028
0x001d 0x00e0
0x001e 0x0004
0x001f 0x0016
0x0020 0x0007
0x0021 0x0009
0x0022 0x000a
0x0023 0x000b
0x0024 0x000d
0x0025 0x000e
0x0026 0x000f
0x0027 0x0033
0x0028 0x0034
0x0029 0x0035
0x002a 0x00e1
0x002b 0x0031
0x002b 0x0032
0x002c 0x001d
0x002d 0x001b
0x002e 0x0006
0x002f 0x0019
0x0030 0x0005
0x0031 0x0011
0x0032 0x0010
0x0033 0x0036
0x0034 0x0037
0x0035 0x0038
0x0036 0x00e5
0x0037 0x0055
0x0038 0x00e2
0x0039 0x002c
0x003a 0x0039
0x003b 0x003a
0x003c 0x003b
0x003d 0x003c
0x003e 0x003d
0x003f 0x003e
0x0040 0x003f
0x0041 0x0040
0x0042 0x0041
0x0043 0x0042
0x0044 0x0043
0x0045 0x0048
0x0046 0x0047
0x0047 0x005f
0x0048 0x0060
0x0049 0x0061
0x004a 0x0056
0x004b 0x005c
0x004c 0x005d
0x004d 0x005e
0x004e 0x0057
0x004f 0x0059
0x0050 0x005a
0x0051 0x005b
0x0052 0x0062
0x0053 0x0063
0x0056 0x0064
0x0057 0x0044
0x0058 0x0045
0x0059 0x0067
0x005c 0x008c
0x0064 0x0068
0x0065 0x0069
0x0066 0x006a
0x0067 0x006b
0x0068 0x006c
0x0069 0x006d
0x006a 0x006e
0x006b 0x006f
0x006c 0x0070
0x006d 0x0071
0x006e 0x0072
0x0070 0x0088
0x0073 0x0087
0x0076 0x0073
0x0076 0x0094
0x0077 0x0093
0x0078 0x0092
0x0079 0x008a
0x007b 0x008b
0x007d 0x0089
0x007e 0x0085
0x00f1 0x0091
0x00f2 0x0090
0x00ff 0x0001
0xe01c 0x0058
0xe01d 0x00e4
0xe035 0x0054
0xe037 0x0046
0xe038 0x00e6
0xe045 0x0053
0xe047 0x004a
0xe048 0x0052
0xe049 0x004b
0xe04b 0x0050
0xe04d 0x004f
0xe04f 0x004d
0xe050 0x0051
0xe051 0x004e
0xe052 0x0049
0xe053 0x004c
0xe05b 0x00e3
0xe05c 0x00e7
0xe05d 0x0065
0xe05e 0x0066
0x0001 0x00ff
0x0004 0x001e
0x0005 0x0030
0x0006 0x002e
0x0007 0x0020
0x0008 0x0012
0x0009 0x0021
0x000a 0x0022
0x000b 0x0023
0x000c 0x0017
0x000d 0x0024
0x000e 0x0025
0x000f 0x0026
0x0010 0x0032
0x0011 0x0031
0x0012 0x0018
0x0013 0x0019
0x0014 0x0010
0x0015 0x0013
0x0016 0x001f
0x0017 0x0014
0x0018 0x0016
0x0019 0x002f
0x001a 0x0011
0x001b 0x002d
0x001c 0x0015
0x001d 0x002c
0x001e 0x0002
0x001f 0x0003
0x0020 0x0004
0x0021 0x0005
0x0022 0x0006
0x0023 0x0007
0x0024 0x0008
0x0025 0x0009
0x0026 0x000a
0x0027 0x000b
0x0028 0x001c
0x0029 0x0001
0x002a 0x000e
0x002b 0x000f
0x002c 0x0039
0x002d 0x000c
0x002e 0x000d
0x002f 0x001a
0x0030 0x001b
0x0031 0x002b
0x0032 0x002b
0x0033 0x0027
0x0034 0x0028
0x0035 0x0029
0x0036 0x0033
0x0037 0x0034
0x0038 0x0035
0x0039 0x003a
0x003a 0x003b
0x003b 0x003c
0x003c 0x003d
0x003d 0x003e
0x003e 0x003f
0x003f 0x0040
0x0040 0x0041
0x0041 0x0042
0x0042 0x0043
0x0043 0x0044
0x0044 0x0057
0x0045 0x0058
0x0046 0xe037
0x0047 0x0046
0x0048 0x0045
0x0049 0xe052
0x004a 0xe047
0x004b 0xe049
0x004c 0xe053
0x004d 0xe04f
0x004e 0xe051
0x004f 0xe04d
0x0050 0xe04b
0x0051 0xe050
0x0052 0xe048
0x0053 0xe045
0x0054 0xe035
0x0055 0x0037
0x0056 0x004a
0x0057 0x004e
0x0058 0xe01c
0x0059 0x004f
0x005a 0x0050
0x005b 0x0051
0x005c 0x004b
0x005d 0x004c
0x005e 0x004d
0x005f 0x0047
0x0060 0x0048
0x0061 0x0049
0x0062 0x0052
0x0063 0x0053
0x0064 0x0056
0x0065 0xe05d
0x0066 0xe05e
0x0067 0x0059
0x0068 0x0064
0x0069 0x0065
0x006a 0x0066
0x006b 0x0067
0x006c 0x0068
0x006d 0x0069
0x006e 0x006a
0x006f 0x006b
0x0070 0x006c
0x0071 0x006d
0x0072 0x006e
0x0073 0x0076
0x0085 0x007e
0x0087 0x0073
0x0088 0x0070
0x0089 0x007d
0x008a 0x0079
0x008b 0x007b
0x008c 0x005c
0x0090 0x00f2
0x0091 0x00f1
0x0092 0x0078
0x0093 0x0077
0x0094 0x0076
0x00e0 0x001d
0x00e1 0x002a
0x00e2 0x0038
0x00e3 0xe05b
0x00e4 0xe01d
0x00e5 0x0036
0x00e6 0xe038
0x00e7 0xe05c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment