C#如何实现锁键盘?
3个回答
展开全部
还是要用钩子,program大概如下。
#include <windows.h>
HHOOK OldHook=NULL;
HINSTANCE hInst=NULL;
int WINAPI DllEntryPoint(HINSTANCE hinst, DWORD dwReason, void*)
{
if (dwReason==DLL_PROCESS_ATTACH)
hInst = hinst;
else if(dwReason==DLL_PROCESS_DETACH)
if (OldHook)
UnhookWindowsHookEx(OldHook);
return 1;
}
long CALLBACK KeyProc(int code, WPARAM wParam, LPARAM lParam)
{
return 1; //锁定任何按键。
}
BOOL _export CALLBACK DisableKB(bool disable)
{
if (disable) {
if (OldHook == NULL)
OldHook = SetWindowsHookEx(WH_KEYBOARD_LL,
(HOOKPROC)KeyProc, hInst, NULL);
return OldHook != NULL;
}
else {
if (OldHook && UnhookWindowsHookEx(OldHook))
OldHook = NULL;
return OldHook == NULL;
}
}
#include <windows.h>
HHOOK OldHook=NULL;
HINSTANCE hInst=NULL;
int WINAPI DllEntryPoint(HINSTANCE hinst, DWORD dwReason, void*)
{
if (dwReason==DLL_PROCESS_ATTACH)
hInst = hinst;
else if(dwReason==DLL_PROCESS_DETACH)
if (OldHook)
UnhookWindowsHookEx(OldHook);
return 1;
}
long CALLBACK KeyProc(int code, WPARAM wParam, LPARAM lParam)
{
return 1; //锁定任何按键。
}
BOOL _export CALLBACK DisableKB(bool disable)
{
if (disable) {
if (OldHook == NULL)
OldHook = SetWindowsHookEx(WH_KEYBOARD_LL,
(HOOKPROC)KeyProc, hInst, NULL);
return OldHook != NULL;
}
else {
if (OldHook && UnhookWindowsHookEx(OldHook))
OldHook = NULL;
return OldHook == NULL;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询