Detecting the Ctrl key at application startup?

When our WPF application starts, Single Sign On is used to log in. To allow testers to simulate other users, we would like the Control button to hold at startup and open a login dialog.

+8
c # wpf
source share
4 answers

This is what I use in a WPF application to check if the control key is held in the main window constructor. It uses System.Windows.Input.Keyboard

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

EDIT - Bug fixed by Coincoin

+7
source share

A universal solution would be p / invoke GetAsyncKeyState(VK_CONTROL) if you cannot find anything built into .NET.

+1
source share

Take a look at this article that used Keys modifiers to find out what you're looking for.

0
source share

Check out the following link ... scroll down to see Jeff Wan's answer.

How to determine the current key pressed?

0
source share

All Articles