如何捕获 c# win 表单应用程序上的键盘敲击 (CTRl + alt +Del)
有没有办法处理 Ctrl+Alt+Del 组合键。以测验应用程序(Win Forms)为例,在测试结束之前用户不应该能够切换到其他窗口。
我能够使用 C# 标准属性单独捕获 Ctrl 和 Alt 击键。但一旦用户按下 Del 键。控制权脱离我的应用程序,由 Windows 处理。
任何想法都会有帮助。
谢谢。
Is there Any way to handle the Ctrl+Alt+Del Key combination. Take for instance in a quiz application (Win Forms), the user should not be able to switch to other windows till the test is over.
I'm able to capture the Ctrl and Alt key strokes individually, using c# standard properties. but once they user hits the Del key . The control goes out of my appliation and windows handles it.
Any thoughts would be helpful.
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据其他答案,似乎这是可以做到的。尽管我强烈反对这样做。举个例子,你的程序应该由于某种原因挂起(上帝禁止......)。那么你会遇到这样的情况:用户唯一能做的就是使用电源按钮关闭计算机(或拔掉插头......)。
这是有充分理由的,这很难做到,而且这些方法的记录很少……
这看起来是唯一可行的方法,来自 Pierre-Alain Vigeant 的评论,如果这是信息亭计算机什么的。那么这样做实际上是有意义的!
Based on other answers, it seems that this is possible to do. Although I highly discourage this. Take for instance that your program should for some reason hang (god forbid...). Then you would have the situation that the only thing the user can do is to turn off the computer with the power button (or pull the plug...).
It is for a good reason that this is difficult to do, and the methods are poorly documented...
The only way this looks like the way to go, is the comment from Pierre-Alain Vigeant if this is a kiosk computer or something. Then it would actually make sense to do this!
我认为这不是一个好方法。
您正在为用户开发应用程序,不应试图阻碍他的一般操作。
对于 Alt+Ctrl+Del 组合键,请阅读这篇文章。
I don't think this is a good approach.
You are developing an application for the user and should not try to hinder his general actions.
For Alt+Ctrl+Del key combination read this article.
AFAIK,Ctrl+Alt+Del 会生成硬件中断,无法通过软件应用程序处理。也许这可以通过系统级键盘挂钩来处理,但我对此也不太确定。
AFAIK, Ctrl+Alt+Del generates a hardware interrupt and cannot be handled through software applications. Probably this can be handled through system-level keyboard hooks but I am not so sure about that either.
嗯,老话题了,没有真正的答案。
简短版本:
长版:
是的,这是可能的。为了能够拦截这些组合键,您需要在内核层提供键盘驱动程序。解释一下原因: 一般来说,Windows 中有两种不同类型的击键。有系统击键(WM_SYSKEYDOWN 或 WM_SYSKEYUP)和非系统击键(WM_KEYDOWN 或 WM_KEYUP)。只有非系统击键可以被钩子中断。这些击键消息在驱动程序中生成,然后传递到系统消息队列中。如果 WM_SYSKEYDOWN 或 WM_SYSKEYUP 在此队列内,则在 Windows 可以自行处理它之前不可能将其删除。
我可以采取什么措施来防止将系统按键推送到 SMQ 中?提供签名的驱动程序来过滤这些驱动程序。自己创建并签署驱动程序并不是最简单的事情。但我们可以使用一些 API。
例如:来自 oblita 的拦截。该 API 提供签名的驱动程序来与键盘或较低的驱动程序交互。
windows下按键事件参考: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx
Hmm, old topic without a real answer.
Short version:
Long version:
Yes, it is possible. To be able to intercept those key combination you need to provide a keyboard driver in the kernel layer. To explain why: In general there are two different types of key strokes in Windows. There are the system keystrokes (WM_SYSKEYDOWN or WM_SYSKEYUP) and the non-system keystrokes (WM_KEYDOWN or WM_KEYUP). Only the non-system keystrokes can be interrupted by a hook. Those keystroke messages are generated in the driver and then passed into the system-message-queue. If a WM_SYSKEYDOWN or WM_SYSKEYUP is inside this queue there is no possiblity on removing it before windows can handle it itself.
What can I do to prevent pushing System Key Strokes into the SMQ? Provide a signed driver to filter those. To create and to sign a driver yourself is not the easiest thing you can do. But there are APIs we can use.
For example: Interception from oblita. That api provides signed driver to interact with the keyboards or lower drivers.
Reference for key events under windows: https://msdn.microsoft.com/en-us/library/windows/desktop/ms646267(v=vs.85).aspx
看看这里:
http://www.thescarms.com/vbasic/StopReBoot.aspx
本质上,对于 Win9x,我们欺骗系统认为屏幕保护程序正在运行(这会禁用 Ctrl-Alt-Delete 序列),对于 WinNT,我们重新映射键盘。
Have a look here:
http://www.thescarms.com/vbasic/StopReBoot.aspx
Essentially for Win9x we trick system to think that the screensaver is running (which disables Ctrl-Alt-Delete sequence) and for WinNT we remap keyboard.
将 Form.TopMost 设置为 true,每毫秒调用 Form.Activate() 并提高进程和入口线程的优先级。
(你瞧,你的应用程序崩溃的可怜用户。)
Set Form.TopMost to true, call Form.Activate() every millisecond and raise the process and entry thread priorities.
(Lo and behold the poor user which your application crashes on.)