简体   繁体   English

如何挂钩Ctrl-Alt-Tab?

[英]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.

相关问题 如何拦截所有关键事件,包括 ctrl+alt+del 和 ctrl+tab? - How can I intercept all key events, including ctrl+alt+del and ctrl+tab? 如何在C#中捕获windows键,alt + tab,ctrl + alt + delete? - How do I trap windows key, alt+tab, ctrl+alt+delete in C#? 如何使用C#中的低级键盘挂钩抑制任务切换键(winkey,alt-tab,alt-esc,ctrl-esc) - How to Suppress task switch keys (winkey, alt-tab, alt-esc, ctrl-esc) using low-level keyboard hook in c# 使用低级键盘挂钩抑制任务切换键(winkey,alt-tab,alt-esc,ctrl-esc) - Suppress task switch keys (winkey, alt-tab, alt-esc, ctrl-esc) using low-level keyboard hook 如何检查 c# 中的鼠标左键是否按下 ctrl、alt? - How can i check if ctrl,alt are pressed on left mouse click in c#? 如何绑定ctrl + 1来选择第一个标签? - How can I bind ctrl+1 to select first tab? 如何在C#控制台应用程序中捕获修改器(ctrl,alt,shift)按键作为单键按下? - How can I capture modifier (ctrl, alt, shift) key presses as a single key press in a C# console app? 如何捕获Alt + Tab - How to capture Alt + Tab 如何模拟shift / ctrl / alt键状态? - How to simulate shift/ctrl/alt key state? 如何从C#winform关闭屏幕键盘并取消所有CTRL或ALT按键 - How do I close the on-screen keyboard from C# winform and cancel any CTRL or ALT keypresses
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM