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 could be caused by the 'Sticky Keys' function (an accessibility option). If you are on Windows 7, click on the start button go to Control Panel, ease of access, change how your keyboard works. Under the option 'Make it easier to type', uncheck 'Turn on Sticky keys' and see if this solves your problem.
Select the key that you want to disable. Under the Keyboard Controls section, select Disable Key. Click on Apply.
To check the physical state of your keyboard, you can try to connect an external keyboard on your system or try an on-screen keyboard and check if the Ctrl key is working on it or not. You can also try to connect your keyboard to another system to check if Ctrl key is working or not.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With