繁体   English   中英

如何在 C++/CX XAML App 中定义全局热键

[英]How to define global hotkey in C++/CX XAML App

我正在尝试在我的 C++/Cx UWP 应用程序中添加对全局热键的支持,但我不知道该怎么做。 我找不到为此的特定事件/处理程序。 此外,来自 winuser.h 的 registerHotKey 在 UWP 下似乎不可用。

提前致谢!

UWP 中的快捷方式可以通过Window.Current.Dispatcher.AcceleratorKeyActivated设置。

这是调用Ctrl + Q的 C# 代码,也许它可以帮助你。

public class MainPage
{
    this.InitializeComponent();
    Window.Current.Dispatcher.AcceleratorKeyActivated += AccelertorKeyActivedHandle;
}

private void AccelertorKeyActivedHandle(CoreDispatcher sender, AcceleratorKeyEventArgs args)
{
    if (args.EventType.ToString().Contains("Down"))
    {
       var ctrl= Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);
       if (ctrl.HasFlag(CoreVirtualKeyStates.Down))
       {
           if (args.VirtualKey == VirtualKey.Q)
           {
              // code here
           }
       }

    }
}

此致。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM