"Michael Moreno" <mi*********************@free.fr> wrote in
news:mn***********************@free.fr:
I would like to cancel an action if the user holds the shift key while
the application is starting-up.
Would you know what is the best way to do so please?
If you do it from within the Form class, you can use the 'ModifierKeys'.
If you want to do it from Main(...) or anywhere else outside of the Form,
then you can use PInvoke:
[DllImport("user32.dll")]
static extern short GetKeyState(VirtualKeyStates nVirtKey);
int ks = GetKeyState(VirtualKeyStates.VK_SHIFT);
if ((ks & 0x80) != 0)
{
// SHIFT KEY is pressed
}
BTW the VirtualKeyStates is an enum defined at pinvoke.net:
http://pinvoke.net/default.aspx/user32.GetKeyState
But if you wanted you could just set the PInvoke signature to use an int
and pass 0x10.
-mdb