在通用 Windows 应用程序中获取键盘状态 [英] Get Keyboard state in Universal Windows Apps
本文介绍了在通用 Windows 应用程序中获取键盘状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检测 Windows 应用程序中的组合键(例如 Control-A
).KeyDown
事件处理程序包含有关上次按下的键的信息.但是如何确定是否也按下了 Control 键?
I want to detect a key combination (e.g. Control-A
) in a Windows App. The KeyDown
event handler has information about the last key pressed. But how do I find out whether the Control key is pressed as well?
推荐答案
您可以使用 CoreVirtualKeyStates.HasFlag(CoreVirtualKeyStates.Down)
来确定 Ctrl 键是否已被按下,像这样 -
You can use CoreVirtualKeyStates.HasFlag(CoreVirtualKeyStates.Down)
to determine is the Ctrl key has been pressed, like this -
Window.Current.CoreWindow.KeyDown += (s, e) =>
{
var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);
if (ctrl.HasFlag(CoreVirtualKeyStates.Down) && e.VirtualKey == VirtualKey.A)
{
// do your stuff
}
};
这篇关于在通用 Windows 应用程序中获取键盘状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文