[英]How to check if a key was pressed in C#? (.NET 6)
I would like to check if the alt
key was pressed in c#. I could only find old information that didn't work.我想检查c#是否按下了
alt
键。我只能找到不起作用的旧信息。 It would be helpful if you send an example with the alt
key.如果您发送一个带有
alt
键的示例将会很有帮助。 Thanks in advance!提前致谢!
If you need to detect a modifier key outside of a KeyEventHandler
method, you can use the static Keyboard
class from System.Windows.Input
.如果您需要在
KeyEventHandler
方法之外检测修改键,您可以使用 static Keyboard
class 来自System.Windows.Input
。
Example from my WPF .NET 6.0 Application on Windows来自我的示例 WPF .NET 6.0 Windows 上的应用程序
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
{
// Do something
}
There was a similar post that provides a solution for this.有一篇类似的帖子为此提供了解决方案。 Look for the answer by Jim Mischel
寻找吉姆·米歇尔的答案
You can use the KeyEventArgs Class您可以使用 KeyEventArgs Class
if (e.Alt)
{
// Alt key was pressed
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.