c++ - Why does the slash key "/" not have an ASCII value of 47? -
i have reassigned hotkey in our game use slash key "/", according ascii table should have value of 47. it's not firing. fires other standard keys. when step through code see keyeventrecord shows key value 191 or 111 if use slash on numeric keyboard. why so? need convert somehow?
just clarification, store key value int.
keyboards not know ascii. know scan codes, vendor-specific ids actual keys.
when processed, scan codes normalized in vendor-independent virtual key codes. 191 vk_oem_2
(used /?
key in keyboards) , 111 vk_divide
.
when dispatched ui windows, virtual key codes converted character codes in wm_char
, wm_unichar
messages. these human-readable characters, such ascii characters (though wm_char
presents characters in ansi/utf-16 encoding, , wm_unichar
in utf-32 encoding).
so, processing keyboard events, such wm_keydown/up
or readconsoleinput()
, reporting virtual key codes when expecting character codes instead.
for many ascii characters, virtual key code , character code same value, eg:
#define vk_back 0x08 #define vk_tab 0x09 #define vk_return 0x0d #define vk_space 0x20 /* * vk_0 - vk_9 same ascii '0' - '9' (0x30 - 0x39) * vk_a - vk_z same ascii 'a' - 'z' (0x41 - 0x5a) */
however, other ascii characters, virtual key code , character code have different values, eg:
#define vk_oem_1 0xba // ';:' #define vk_oem_plus 0xbb // '+' country #define vk_oem_comma 0xbc // ',' country #define vk_oem_minus 0xbd // '-' country #define vk_oem_period 0xbe // '.' country #define vk_oem_2 0xbf // '/?' #define vk_oem_3 0xc0 // '`~' #define vk_oem_4 0xdb // '[{' #define vk_oem_5 0xdc // '\|' #define vk_oem_6 0xdd // ']}' #define vk_oem_7 0xde // ''"'
read msdn more information: