开发者

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 dia开发者_开发知识库log.


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. It uses System.Windows.Input.Keyboard

if ((Keyboard.Modifiers & ModifierKeys.Control) > 0)
    PromptForMarketSelection();

EDIT - corrected bug pointed out by Coincoin


A universal solution would be to p/invoke GetAsyncKeyState(VK_CONTROL), in case you can't find anything built into .NET.


Take a look at this article it used ModifierKeys to find out what you are looking for


Check out the following link...scroll down to look at the answer by Jeff Wain.

How to detect the currently pressed key?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜