如何在 C++/CX 中定义全局热键 XAML App
How to define global hotkey in C++/CX XAML App
我正在尝试在我的 C++/Cx UWP 应用程序中添加对全局热键的支持,但我不知道该怎么做。
我无法为此找到具体的 event/handler。此外,winuser.h 的 registerHotKey 在 UWP 下似乎不可用。
提前致谢!
可以通过 Window.Current.Dispatcher.AcceleratorKeyActivated
.
设置 UWP 中的快捷方式
这是调用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
}
}
}
}
此致。
我正在尝试在我的 C++/Cx UWP 应用程序中添加对全局热键的支持,但我不知道该怎么做。 我无法为此找到具体的 event/handler。此外,winuser.h 的 registerHotKey 在 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
}
}
}
}
此致。