[英]Detecting Ctrl key being held down on application startup?
When our WPF application starts, it uses Single Sign On to log in. To allow testers to simulate other users, we'd like to detect the Control button being held down on startup, and pop up a login dialog.当我们的 WPF 应用程序启动时,它使用 Single Sign On 登录。为了让测试人员模拟其他用户,我们希望检测到在启动时按住 Control 按钮,并弹出登录对话框。
This is what I use in a WPF app to check if the control key is being held down in the constructor of the main Window.这是我在 WPF 应用程序中使用的,用于检查主 Window 的构造函数中是否按住了控制键。 It usesSystem.Windows.Input.Keyboard它使用System.Windows.Input.Keyboard
if ((Keyboard.Modifiers & ModifierKeys.Control) > 0)
PromptForMarketSelection();
EDIT - corrected bug pointed out by Coincoin编辑 - 纠正了 Coincoin 指出的错误
A universal solution would be to p/invoke GetAsyncKeyState(VK_CONTROL)
, in case you can't find anything built into .NET.一个通用的解决方案是 p/invoke GetAsyncKeyState(VK_CONTROL)
,以防您找不到 .NET 内置的任何东西。
Check out the following link...scroll down to look at the answer by Jeff Wain.查看以下链接...向下滚动以查看 Jeff Wain 的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.