简体   繁体   中英

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.

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 usesSystem.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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM