Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SetWindowsHookEx键盘在右移时不响应 我尝试使用C++中的Windows API和 StWistWOShOOKEX WHKEYBOADARLLL似乎没有从右移位键(QWERTY键盘右侧的移位键,低于Enter键)获得事件。它与左Shift键一起工作。如何解决此问题 #include "stdafx.h" #include <cstdlib> #include <fstream> #include <iostream> #include <string> #include <windows.h> #include <string> #include <shlobj.h> #include <Shlwapi.h> #include <stdio.h> #include <aclapi.h> #include <tchar.h> #include <iostream> #include <fstream> #include <future> #include <stdlib.h> #include <random> #include <ctime> #include <time.h> #include <Lmcons.h> HHOOK kbdhook; /* Keyboard hook handle */ bool running; /* Used in main loop */ __declspec(dllexport) LRESULT CALLBACK handlekeys(int code, WPARAM wp, LPARAM lp) { static bool capslock = false; static bool shift = false; char tmp[0xFF] = {0}; std::string str; DWORD msg = 1; KBDLLHOOKSTRUCT st_hook = *((KBDLLHOOKSTRUCT*)lp); msg += (st_hook.scanCode << 16); msg += ((st_hook.flags & LLKHF_EXTENDED) << 24); GetKeyNameText(msg, tmp, 0xFF); str = std::string(tmp); if (code == HC_ACTION && (wp == WM_SYSKEYDOWN || wp == WM_KEYDOWN )) { MessageBox(NULL,str.c_str(),NULL,MB_OK); } return CallNextHookEx(kbdhook, code, wp, lp); } LRESULT CALLBACK windowprocedure(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_CLOSE: case WM_DESTROY: running = false; break; default: /* Call default message handler */ return DefWindowProc(hwnd, msg, wp, lp); } return 0; } int WINAPI WinMain(HINSTANCE thisinstance, HINSTANCE previnstance, LPSTR cmdline, int ncmdshow) { HWND hwnd; HWND fgwindow = GetForegroundWindow(); MSG msg; WNDCLASSEX windowclass; HINSTANCE modulehandle; modulehandle = GetModuleHandle(NULL); kbdhook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)handlekeys, modulehandle, NULL); running = true; while (running) { if (!GetMessage(&msg, NULL, 0, 0)) running = false; TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } #包括“stdafx.h” #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 HHOOK-kbdhook;/*键盘钩柄*/ 布尔运行;/*用于主回路*/ __declspec(dllexport)LRESULT回调handlekeys(int代码、WPARAM wp、LPARAM lp) { 静态布尔-卡普斯洛克=假; 静态布尔移位=假; 字符tmp[0xFF]={0}; std::字符串str; DWORD msg=1; KBDLLHOOKSTRUCT st_hook=*((KBDLLHOOKSTRUCT*)lp); msg+=(st_hook.scanCode_C++_Windows_Winapi_Visual C++_Keyboard Hook - Fatal编程技术网

SetWindowsHookEx键盘在右移时不响应 我尝试使用C++中的Windows API和 StWistWOShOOKEX WHKEYBOADARLLL似乎没有从右移位键(QWERTY键盘右侧的移位键,低于Enter键)获得事件。它与左Shift键一起工作。如何解决此问题 #include "stdafx.h" #include <cstdlib> #include <fstream> #include <iostream> #include <string> #include <windows.h> #include <string> #include <shlobj.h> #include <Shlwapi.h> #include <stdio.h> #include <aclapi.h> #include <tchar.h> #include <iostream> #include <fstream> #include <future> #include <stdlib.h> #include <random> #include <ctime> #include <time.h> #include <Lmcons.h> HHOOK kbdhook; /* Keyboard hook handle */ bool running; /* Used in main loop */ __declspec(dllexport) LRESULT CALLBACK handlekeys(int code, WPARAM wp, LPARAM lp) { static bool capslock = false; static bool shift = false; char tmp[0xFF] = {0}; std::string str; DWORD msg = 1; KBDLLHOOKSTRUCT st_hook = *((KBDLLHOOKSTRUCT*)lp); msg += (st_hook.scanCode << 16); msg += ((st_hook.flags & LLKHF_EXTENDED) << 24); GetKeyNameText(msg, tmp, 0xFF); str = std::string(tmp); if (code == HC_ACTION && (wp == WM_SYSKEYDOWN || wp == WM_KEYDOWN )) { MessageBox(NULL,str.c_str(),NULL,MB_OK); } return CallNextHookEx(kbdhook, code, wp, lp); } LRESULT CALLBACK windowprocedure(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_CLOSE: case WM_DESTROY: running = false; break; default: /* Call default message handler */ return DefWindowProc(hwnd, msg, wp, lp); } return 0; } int WINAPI WinMain(HINSTANCE thisinstance, HINSTANCE previnstance, LPSTR cmdline, int ncmdshow) { HWND hwnd; HWND fgwindow = GetForegroundWindow(); MSG msg; WNDCLASSEX windowclass; HINSTANCE modulehandle; modulehandle = GetModuleHandle(NULL); kbdhook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)handlekeys, modulehandle, NULL); running = true; while (running) { if (!GetMessage(&msg, NULL, 0, 0)) running = false; TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } #包括“stdafx.h” #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 HHOOK-kbdhook;/*键盘钩柄*/ 布尔运行;/*用于主回路*/ __declspec(dllexport)LRESULT回调handlekeys(int代码、WPARAM wp、LPARAM lp) { 静态布尔-卡普斯洛克=假; 静态布尔移位=假; 字符tmp[0xFF]={0}; std::字符串str; DWORD msg=1; KBDLLHOOKSTRUCT st_hook=*((KBDLLHOOKSTRUCT*)lp); msg+=(st_hook.scanCode

SetWindowsHookEx键盘在右移时不响应 我尝试使用C++中的Windows API和 StWistWOShOOKEX WHKEYBOADARLLL似乎没有从右移位键(QWERTY键盘右侧的移位键,低于Enter键)获得事件。它与左Shift键一起工作。如何解决此问题 #include "stdafx.h" #include <cstdlib> #include <fstream> #include <iostream> #include <string> #include <windows.h> #include <string> #include <shlobj.h> #include <Shlwapi.h> #include <stdio.h> #include <aclapi.h> #include <tchar.h> #include <iostream> #include <fstream> #include <future> #include <stdlib.h> #include <random> #include <ctime> #include <time.h> #include <Lmcons.h> HHOOK kbdhook; /* Keyboard hook handle */ bool running; /* Used in main loop */ __declspec(dllexport) LRESULT CALLBACK handlekeys(int code, WPARAM wp, LPARAM lp) { static bool capslock = false; static bool shift = false; char tmp[0xFF] = {0}; std::string str; DWORD msg = 1; KBDLLHOOKSTRUCT st_hook = *((KBDLLHOOKSTRUCT*)lp); msg += (st_hook.scanCode << 16); msg += ((st_hook.flags & LLKHF_EXTENDED) << 24); GetKeyNameText(msg, tmp, 0xFF); str = std::string(tmp); if (code == HC_ACTION && (wp == WM_SYSKEYDOWN || wp == WM_KEYDOWN )) { MessageBox(NULL,str.c_str(),NULL,MB_OK); } return CallNextHookEx(kbdhook, code, wp, lp); } LRESULT CALLBACK windowprocedure(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_CLOSE: case WM_DESTROY: running = false; break; default: /* Call default message handler */ return DefWindowProc(hwnd, msg, wp, lp); } return 0; } int WINAPI WinMain(HINSTANCE thisinstance, HINSTANCE previnstance, LPSTR cmdline, int ncmdshow) { HWND hwnd; HWND fgwindow = GetForegroundWindow(); MSG msg; WNDCLASSEX windowclass; HINSTANCE modulehandle; modulehandle = GetModuleHandle(NULL); kbdhook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)handlekeys, modulehandle, NULL); running = true; while (running) { if (!GetMessage(&msg, NULL, 0, 0)) running = false; TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } #包括“stdafx.h” #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括 HHOOK-kbdhook;/*键盘钩柄*/ 布尔运行;/*用于主回路*/ __declspec(dllexport)LRESULT回调handlekeys(int代码、WPARAM wp、LPARAM lp) { 静态布尔-卡普斯洛克=假; 静态布尔移位=假; 字符tmp[0xFF]={0}; std::字符串str; DWORD msg=1; KBDLLHOOKSTRUCT st_hook=*((KBDLLHOOKSTRUCT*)lp); msg+=(st_hook.scanCode,c++,windows,winapi,visual-c++,keyboard-hook,C++,Windows,Winapi,Visual C++,Keyboard Hook,左移位与右移位显示在KBDLLHOOKSTRUCT的vkCode字段中。您使用的是扫描码的键名;右移位键名为“shift”,就像键盘上所说的那样 显然,right shift以扩展标志集结束,这导致GetKeyNameText在错误的表中查找。删除扩展标志以键名“right shift”结束 msg+=(st_hook.scanCode此解决方案不依赖特定代码 if (st_hook.vkCode != VK_RSHIFT) msg += ((st_hook.flags & LLKH

左移位与右移位显示在
KBDLLHOOKSTRUCT
vkCode
字段中。您使用的是扫描码的键名;右移位键名为“shift”,就像键盘上所说的那样

显然,right shift以扩展标志集结束,这导致GetKeyNameText在错误的表中查找。删除扩展标志以键名“right shift”结束


msg+=(st_hook.scanCode此解决方案不依赖特定代码

if (st_hook.vkCode != VK_RSHIFT)
  msg += ((st_hook.flags & LLKHF_EXTENDED) << 24);
if(st_hook.vkCode!=VK_RSHIFT)

msg+=((st_hook.flags&LLKHF_EXTENDED)@paulm Right shift在警报中显示一个blanco字符串。然而,Left shift在警报中显示一个“shift”字符串。这是GetKeyNameText()中的一个怪癖。shift键有点特殊,它们生成相同的虚拟键码,但有不同的扫描码。它只是不能正确处理右shift键的扫描码。您必须克服这个限制。@HansPassant删除“msg+=(st_hook.scanCode@HansPassant但是…如果我删除带有“msg+=”的行((st_hook.flags&LLKHF_EXTENDED)未定义字符或结果中的“blanco”为空。但是……如果我删除与“msg+=”((st_hook.flags&LLKHF_EXTENDED)@user10056相关的行,那么答案是明确忽略右移的扩展标志(扫描代码0x3a)。其他键(插入、删除等)需要扩展标志来获得正确的行为。我知道这些API的事情,因为我在Windows上工作。要明确的是:“if(st_hook.scanCode!=0x3a){}”并没有解决问题。“I work on Windows”看起来我的右移位标记为scanCode“54”,如果(st_hook.scanCode!=54){}似乎工作得更好一些……但它显示“Alt Gr as”ctrl+alt“不知何故。。
if (st_hook.vkCode != VK_RSHIFT)
  msg += ((st_hook.flags & LLKHF_EXTENDED) << 24);