Tuesday, August 4, 2009

How to tell in VB.NET or C# if the Ctrl or Shift Key are being pressed

Sometimes you may need to know if the Ctrl or Shift key is being pressed by checking its state instead of using a key event. Also, most solutions to this problem involve some pinvoking and the win32api GetKeyState, but it turns out to be very simple as this posting describes:

http://predicatet.blogspot.com/2008/04/how-to-detect-if-shift-or-control-key.html


Here is the gist:

if (Control.ModifierKeys == Keys.Control)
{

}

No comments: