JimR123b
asked on
Detect keys down on application startup?
Hi,
I have written in C#. I would like the application to start in a "support mode" if the user is holding down Ctrl+Shift+S when the application starts.
As I need to detect the "support mode" keys before the application starts (i.e. the main form loads), I can't do it on the keydown event of the main form. This is because some of the things on the main form get initialised differently in support mode.
I can't find a way of getting the current keys pressed without responding to events.
How can I do this?
I have written in C#. I would like the application to start in a "support mode" if the user is holding down Ctrl+Shift+S when the application starts.
As I need to detect the "support mode" keys before the application starts (i.e. the main form loads), I can't do it on the keydown event of the main form. This is because some of the things on the main form get initialised differently in support mode.
I can't find a way of getting the current keys pressed without responding to events.
How can I do this?
In there, you could set up a singleton GlobalConfig class that contains members that you want to init.
Your main form can then also reference the singleton, e.g. GlobalConfig.GetSingleton. somesettin g
Your main form can then also reference the singleton, e.g. GlobalConfig.GetSingleton.
ASKER
How do I get the current state of the keys pressed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I perhaps should have said, I'm using .Net Framework 3.5.
It appears that the Keyboard class is .Net 4?... http://msdn.microsoft.com/ en-us/libr ary/system .windows.i nput.keybo ard.iskeyd own.aspx
That's the kind of thing I'm looking for, but for .Net 3.5.
It appears that the Keyboard class is .Net 4?... http://msdn.microsoft.com/
That's the kind of thing I'm looking for, but for .Net 3.5.
Please see the above link.
The class is created in the link, for pre .Net 4.
The class is created in the link, for pre .Net 4.
ASKER
...Also, I can't use Control.ModifierKeys because I don't have a handle on a control yet, as it is needed before the main form is created.
Control is a static reference to the Control class, not an instance of a control.
ASKER
Ah, I see. I did try code completion on "Control." to see what came up, and it only came up with a few things, none of which were "ModifierKeys". I've tried it in another class now, and I see "ModifierKeys" :)
...but how do I get the state of Keys.S without the Keyboard class? Is there something similar in Control?
...but how do I get the state of Keys.S without the Keyboard class? Is there something similar in Control?
ASKER
Sorry, didn't see the definition of the class Keyboard in http://www.switchonthecode .com/tutor ials/winfo rms-access ing-mouse- and-keyboa rd-state
Enum Keys
Namespace: System.Windows.Forms
http://msdn.microsoft.com/en-us/library/system.windows.forms.keys%28v=VS.90%29.aspx
Namespace: System.Windows.Forms
http://msdn.microsoft.com/en-us/library/system.windows.forms.keys%28v=VS.90%29.aspx
http://www.java2s.com/Tutorial/CSharp/0470__Windows-Presentation-Foundation/InheritApplicationclassandoverrideOnStartup.htm