How to detect the currently pressed key?

if ((Control.ModifierKeys & Keys.Shift) != 0) 

This will also be true if Ctrl+Shift is down. If you want to check whether Shift alone is pressed,

if (Control.ModifierKeys == Keys.Shift)

If you’re in a class that inherits Control (such as a form), you can remove the Control.

Leave a Comment