c# - 如何检测 WPF 中的修饰键状态?

标签 c# .net wpf keyboard

无论 Control、Shift、Alt 按钮是否按下,是否有一些全局构造可以在我需要访问时使用?例如在 TreeViewMouseDown 事件中。

如果是怎么办?

最佳答案

使用类 Keyboard .使用Keyboard.IsKeyDown您可以检查 Control、Shift、Alt 现在是否已关闭。

对于类次:

if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
{ /* Your code */ }

对于控制:

if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{ /* Your code */ }

对于 Alt:

if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))
{ /* Your code */ }

关于c# - 如何检测 WPF 中的修饰键状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5750722/

相关文章:

c# - 何时覆盖以及何时订阅委托(delegate)?

c# - WPF 中的 FlowLayout ItemsControl

c# - 绑定(bind)到 ObservableCollection 附加属性

c# - Azure:如何在表存储中保存 IDictionary<String>?

c# - 启动 Visual Studio 2010 时更改默认环境设置

c# - WPF XAML 和 MinWidth 和 MaxWidth

c# - WPF View-ModelView 绑定(bind)需要帮助请

c# - 如何制作数组大小上限

c# - 计算带宽

c# - 保存身份验证 token 的最佳方法?