我想映射键盘布局上不存在的字符吗?
我的键盘布局为italian,字符为〜和`
当我按AltGr(VK_RMENU)+ VK_OEM_4或VK_OEM_6时,我想重新映射。
但是这些字符不在Virtual-Key Codes列表中,所以我认为我不会使用SendInput进行重新映射...
对于其他字符 SendInput 来说
答案 0 :(得分:0)
但是此字符不在“虚拟键代码”列表中,所以我认为我不知道 使用SendInput重新映射...
〜和` 在Virtual-Key Codes list中。它是 VK_OEM_3(0xC0)。
您可以使用SendInput输入〜和`,如下所示:
UINT result = 0;
DWORD errCode = 0;
tagINPUT inputArray[2] = {};
tagKEYBDINPUT keyboardInput[2] = {};
keyboardInput[1].wVk = 0xC0; // Virtual-Key code for the '`~' key.
keyboardInput[1].wScan = 0x29; // Scan code for the '`~' key.
inputArray[1].type = INPUT_KEYBOARD;
inputArray[1].ki = keyboardInput[1];
keyboardInput[0].wVk = 0x10; // Virtual-Key code for the 'shift' key.
keyboardInput[0].wScan = 0x2A; // Scan code for the 'shift' key.
inputArray[0].type = INPUT_KEYBOARD;
inputArray[0].ki = keyboardInput[0];
// Enter '~' (shift + '`~' key)
result = SendInput(2, inputArray, sizeof(tagINPUT));
errCode = GetLastError();
// Enter '`'
result = SendInput(1, &inputArray[1], sizeof(tagINPUT));
errCode = GetLastError();
如果要输入这两个字符,SendMessage也可以执行此操作(similar issue):
LPCWSTR Target_window_Name = TEXT("Untitled - Notepad"); //<- Has to match window name
HWND hWindowHandle = FindWindow(NULL, Target_window_Name);
HWND EditClass = FindWindowEx(hWindowHandle, NULL, L"Edit", NULL);
SendMessage(EditClass, WM_KEYDOWN, 0xC0, 0x002C0001); //VK_OEM_3 0xC0
SendMessage(EditClass, WM_CHAR, 0x7E, 0x002C0001); //~
SendMessage(EditClass, WM_KEYUP, 0xC0, 0xC02C0001);
SendMessage(EditClass, WM_KEYDOWN, 0xC0, 0x002C0001); //VK_OEM_3 0xC0
SendMessage(EditClass, WM_CHAR, 0x60, 0x002C0001); //`
SendMessage(EditClass, WM_KEYUP, 0xC0, 0xC02C0001);
引用:“ SendInput”“ SendMessage”
对于扫描代码,您可以搜索“键盘扫描代码规范-Microsoft”。