Detecting if a key is pressed outside the key events
-
I want to detect if a key is held down during the start up of my program, i.e. in
static void Main()
Is this possible to achieve? I want to make a safe mode that will be entered if the user holds down the shift key when starting the program.
-
I want to detect if a key is held down during the start up of my program, i.e. in
static void Main()
Is this possible to achieve? I want to make a safe mode that will be entered if the user holds down the shift key when starting the program.
Have a look at: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx[^] Im not 100% sure that it does work at program startup or if it have some assoiciaton with the wnd proc. But it I would guess it does work w/o wnd proc. If so, then you can simply call it ad the app main method.
-
I want to detect if a key is held down during the start up of my program, i.e. in
static void Main()
Is this possible to achieve? I want to make a safe mode that will be entered if the user holds down the shift key when starting the program.
One way I can think of is to add a reference to
System.Windows.Forms
if you don't have it already and use the following:static void Main(string[] args)
{
Keys modifiers = Control.ModifierKeys;
Console.WriteLine(modifiers);
}The modifiers enumeration will have the keys held down (only works for the modifier keys, i.e.
Control
,Shift
,Alt
etc).
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
-
One way I can think of is to add a reference to
System.Windows.Forms
if you don't have it already and use the following:static void Main(string[] args)
{
Keys modifiers = Control.ModifierKeys;
Console.WriteLine(modifiers);
}The modifiers enumeration will have the keys held down (only works for the modifier keys, i.e.
Control
,Shift
,Alt
etc).
I doubt it. If it isn't intuitive then we need to fix it. - Chris Maunder
Thanks! This works like a charm!