How to build the vkCode value of WM_CHAR lParam for non-alpha characters !@#$%¨&*()-= etc?
test("a#b@c&d*ef-g+!h", hWnd); struct extraKeyInfo { unsigned short repeatCount = 1; unsigned char scanCode; bool extendedKey = 0; bool contextCode = 0; bool prevKeyState = 0; bool transitionState = 0; operator unsigned int() { return repeatCount | (scanCode << 16) | (extendedKey << 24) | (contextCode << 29) | (prevKeyState << 30) | (transitionState << 31); } }; void test(const char* str, HWND hWnd) { extraKeyInfo lParam = {}; for (int i = 0; i < strlen(str); i++) { short vkCode = LOBYTE(VkKeyScan(str[i])); // vkCode 32 = space. if ((!isalpha(str[i])) && (vkCode != 32)) vkCode << 19; /* <= my doubt lies here */ lParam.scanCode = MapVirtualKey(vkCode, MAPVK_VK_TO_VSC); PostMessage(hWnd, WM_CHAR, vkCode, lParam); } return; }
lParamfor non-alpha char.vkCode << 19;is definitely a problem (or two). 1.vkCodeis ashort, which contains 16 bits, and it is shifted 19 positions. That is not going to work well. And 2. The result isn't stored anywhere.