[英]How can I hook Ctrl-Alt-Tab?
I am trying to hook the keyboard in my program, but there is something that I can't accomplish. 我试图在我的程序中挂钩键盘,但有一些我无法完成的事情。 The method below is the most important part in my class where I handle certain key combinations.
下面的方法是我班级中最重要的部分,我处理某些键组合。 All of them work, but I also want to hook Ctrl-Alt-Tab.
所有这些都有效,但我也想挂钩Ctrl-Alt-Tab。 I've spent hours trying to figure out what to do, but I came empty handed.
我花了好几个小时试图弄清楚要做什么,但我空手而归。 How can I hook this combination as well?
我怎么能挂钩这个组合呢?
More Information can be found here: 更多信息可以在这里找到:
http://msdn.microsoft.com/en-us/library/ms644967(VS.85).aspx http://msdn.microsoft.com/en-us/library/ms644967(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms927178.aspx http://msdn.microsoft.com/en-us/library/ms927178.aspx
private static IntPtr KeyboardHookHandler(int nCode, IntPtr wParam, KBDLLHookStruct lParam)
{
if (nCode == 0)
{
if ( ( (lParam.flags == 32) && (lParam.vkCode == 0x09) ) || // Alt+Tab
( (lParam.flags == 32) && (lParam.vkCode == 0x1B) ) || // Alt+Esc
( (lParam.flags == 0 ) && (lParam.vkCode == 0x1B) ) || // Ctrl+Esc
( (lParam.flags == 1 ) && (lParam.vkCode == 0x5B) ) || // Left Windows Key
( (lParam.flags == 1 ) && (lParam.vkCode == 0x5C) ) || // Right Windows Key
( (lParam.flags == 32) && (lParam.vkCode == 0x73) ) || // Alt+F4
( (lParam.flags == 32) && (lParam.vkCode == 0x20) )) // Alt+Space
{
return new IntPtr(1);
}
}
return CallNextHookEx(hookPtr, nCode, wParam, lParam);
}
Worlds, you are trapping the keys correctly but you need to perform bitwise AND operations on your lParam.flags to determine whether more than one modifier key was pressed. 世界,您正在正确捕获键,但您需要对lParam.flags执行按位AND操作以确定是否按下了多个修改键。
This is off the top of my head but i think the code that looks like this: 这是我的头脑,但我认为代码看起来像这样:
(lParam.flags == 32)
should look something like: 应该看起来像:
((lParam.flags & 32 == 32) && (lParam.flags & 16 == 16))
32 and 16 are arbitrary in this example. 在这个例子中,32和16是任意的。 You need to figure out what values ALT and CTRL actually are.
您需要弄清楚ALT和CTRL实际上是什么值。 They will be 1, 2, 4 ... 16, 32 etc. so that they can be OR'ed together into a single value.
它们将是1,2,4 ... 16,32等,以便它们可以一起“或”成单个值。
It might be worth your while to check out this article by Paul DiLascia who shows how to trap the keys Ctrl+Alt+Del combination here . 阅读Paul DiLascia撰写的文章可能值得您花些时间来展示如何在此处捕获Ctrl + Alt + Del组合键。 There is a version available for the .NET framework found on CodeProject here and here .
没有可用于在CodeProject上发现了.NET框架版本在这里和这里 。
Hope this helps, Best regards, Tom. 希望这会有所帮助,最好的问候,汤姆。
You should subclass the win32 message pump. 您应该为win32消息泵创建子类。
Maybe you will get some ideas from this VC6 project Trap CtrlAltDel; 也许你会从这个VC6项目Trap CtrlAltDel得到一些想法; Hide Application in Task List on Win2000/XP
在Win2000 / XP上的任务列表中隐藏应用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.