在 Windows C++ 中禁用键盘?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1214648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Disabling the keyboard in windows c++?
提问by user37875
How can I completely disable the keyboard using c++ in windows? And by completely disable I mean so even Ctrl+Alt+Deletedoesn't work. I did consider using a keyboard driver but I think you need to restart the computer after it is installed, but since I only need to disable it for a couple minutes that wouldn't really work.
如何在 Windows 中使用 C++ 完全禁用键盘?并通过完全禁用我的意思是这样即使Ctrl+ Alt+Delete不起作用。我确实考虑过使用键盘驱动程序,但我认为您需要在安装后重新启动计算机,但因为我只需要禁用它几分钟,这实际上不起作用。
回答by Christopher
This is not really possible.
这是不可能的。
WinLogon is designed as the one process that intercepts the Ctrl+Alt+Delkey press, even when all other things hang or die. This is the failsafe against malicious sessions, etc. So there is no obvious workaround.
WinLogon 被设计为拦截Ctrl+ Alt+Del键按下的一个进程,即使在所有其他事情挂起或死亡时也是如此。这是针对恶意会话等的故障保护。因此没有明显的解决方法。
Maybe a keyboard filter driver would make your request possible, but that is a real kernel-driver.
也许键盘过滤器驱动程序会使您的请求成为可能,但那是一个真正的内核驱动程序。
回答by Mike McQuaid
You can't disable Ctrl-Alt-Deletewithout removing the keyboard or replacing the keyboard driver, it generates a kernel level notification.
您不能禁用Ctrl- Alt-Delete无需拆卸键盘或更换键盘驱动程序,它会生成一个内核级的通知。
回答by Indy9000
You could install a keyboard hook and filter out the messages, but you might need to have your application as the top most window. Even then Ctrl+Alt+Delwould not get filtered out.
您可以安装键盘挂钩并过滤掉消息,但您可能需要将应用程序作为最顶部的窗口。即使这样Ctrl+ Alt+Del不会得到过滤掉。
Here's SetWindowsHookExon MSDN
这是MSDN 上的SetWindowsHookEx
Example of Hooking the Keyboard
挂接键盘的例子
回答by Kirill V. Lyadvinsky
You could use BlockInputfunction. But it doesn't block CTRL + ALT + DEL.
您可以使用BlockInput功能。但它不会阻止CTRL + ALT + DEL.
回答by selbie
Ok, here goes several random suggestions. I don't have a definitite answer, but here's where I would start:
好的,这里有几个随机建议。我没有明确的答案,但这是我要开始的地方:
1) SetupDiRemoveDevice is probably the API you want to call. Although to call it, you'll need to make a lot of other device enumeration calls. Enumerate your HID and USB devices and find the keyboard. Start by looking for the VID/PID of the actual device for starters.
1) SetupDiRemoveDevice 可能是您要调用的 API。尽管要调用它,您还需要进行许多其他设备枚举调用。枚举您的 HID 和 USB 设备并找到键盘。首先为初学者寻找实际设备的 VID/PID。
2) Delete the drivers kdbclass.sys and kbdhid.sys. You'll be fighting Windows system file to do this. I have no idea if this will work, but sounds interesting and simple.
2) 删除驱动程序kdbclass.sys 和kbdhid.sys。你将与 Windows 系统文件作斗争来做到这一点。我不知道这是否可行,但听起来很有趣也很简单。
3) Write a USB filter driver. Your driver will need to know (or be passed) the vid/pid of the device to filter on, but it might work.
3) 编写一个USB过滤器驱动程序。您的驱动程序需要知道(或通过)要过滤的设备的 vid/pid,但它可能会起作用。