Scan codes are raw key identifiers returned from the keyboard. Thus, 101 keyboard keyboards (theoretically) will have 101 unique scan codes that it can return. (see footnote 1)
Virtual key codes are a separate set of codes that represent a key on an idealized keyboard. No matter where on the real keyboard there is a TAB key and which scancode is used for it, the virtual key code is always VK_TAB. windows.h defines VK_xxx codes for non-printable virtual keys, for printable ones, the virtual key code matches the ASCII value.
But virtual key codes are still key codes. "A" and "a" have the same virtual key code, so if you want to send "A", you need to send VK_SHIFT down, then "a" down, then "a" up, then VK_SHIFT up.
VkKeyScanEx() converts a character to a scan key and a shift state. See the quote below http://msdn.microsoft.com/en-us/library/ms646332(VS.85).aspx
If the function succeeds, the low byte of the return value contains the virtual key code, and the high byte contains the shift state, which may be a combination of the following flag bits.
So you cannot just take a return from VkKeyScanEx (), you need to check if the shift flag is checked. and send the shift key as a separate keystroke
SHORT vk = VkKeyScanEx(c, ...); if (vk & 0x100) // check upper byte for shift flag { // send a shift key down } if (vk & 0x200) // check for ctrl flag { // send a ctrl key down } input.ki.wVk = vk & 0xFF; // send keyup for each of the keydown
You also need to send a key for each keystroke.
Footnote:
1 This is only theoretically, in practice, standard PC keyboards mimic an old IBM keyboard that you cannot even get, so some keys can return 2 different scan codes based on a different key, while others in other cases, two keys can return the same scan code .
John knoeller
source share