简体   繁体   English

取消处理(取消注册)系统范围的“HotKey”

[英]Unhandling (unregistering) a system-wide 'HotKey'

I have defined a HotKey Ctrl + Space to activate my Windows Form. 我已经定义了一个HotKey Ctrl + Space来激活我的Windows窗体。 When the form handles this HotKey , this event is not seen by the system. 当表单处理此HotKey ,系统不会看到此事件。 Is there subsequently any way to unhandle these keystrokes? 有没有办法解开这些击键? (That is, unregister the HotKey .) (即取消注册HotKey 。)

Here is what I have tried: 这是我尝试过的:

private int tuyen_HotKey_Active = 1208132019;

private void Reg_HotKey(bool mode)
{
    if (mode)
    {
        RegisterHotKey(this.Handle, tuyen_HotKey_Active, 2, 32); // Ctrl + Space
    }
    else
    {
        UnregisterHotKey(this.Handle, tuyen_HotKey_Active);
    }
}

protected override void WndProc(ref Message m)
{            
    if (m.Msg == 0x0312) if(m.WParam.ToInt32() == tuyen_HotKey_Active)
    {
        // Do something here. I want Ctrl + Space keystroke to be
        // unhandled here so that it can be seen by the system.
    }
    base.WndProc(ref m);
}

Create a global bool variable. 创建一个全局bool变量。 Set its value to false. 将其值设置为false。

In Windows KeyDown event check if that bool variable is true return from method. 在Windows KeyDown事件中检查bool变量是否为true返回方法。

When you want to unhandle these keystrokes set its value to true and when you want to handle these keystrokes set its value to false. 如果要取消处理这些击键,请将其值设置为true,当您想要处理这些击键时,请将其值设置为false。

public bool flag = false;

public void Window_KeyDown(object sender, KeyEventArgs e)
{
    if (flag)
        return;

    //.. Code Here something
}

Now you just have to set this flag value to handle or unhandle your keystrokes. 现在,您只需设置此标志值即可处理或取消处理您的击键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与“系统级”媒体播放器互动 - Interact with “system-wide” media player 是.net系统范围内的垃圾收集器还是应用程序范围内的垃圾收集器? - Is the garbage collector in .net system-wide or application-wide? .NET系统范围内的EventWaitHandle名称允许的字符 - .NET system-wide EventWaitHandle name allowed characters 从DB处理队列时,系统范围互斥的替代方案? - alternatives to system-wide mutex when processing queue from DB? C#异步接收会导致系统范围的网络崩溃! - C# asynchronous receive causes system-wide network crash! 应用程序如何与系统范围的文本选择挂钩? - How can an app hook into text selection system-wide? Windows 7和8中的系统范围设置-注册表不再有用吗? - System-wide setting in Windows 7 and 8 - Registry is no longer useful? 是否可以定义在整个系统范围内使用的自定义URI方案? - Is possible to define custom URI scheme used system-wide? 如何在 .NET Core 中设置全局环境变量(用户范围或系统范围) - How to set a global environment variable in .NET Core (user-wide or system-wide) 设计Qn RE:系统范围的计时器(C#)。 什么计时器在哪一层? - Design Qn RE: System-wide timer (C#). What timer in what layer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM