Viesturs
Viesturs

Reputation: 1691

How to detect shift key pressed state when on mouse move

I'm trying to show a zoomed in overlay on an image when mouse over and shift key pressed.

The problem is that user might have pressed the shift key before even the window has focus, so KeyDown monitoring is not a solution.

Is there a way to access modifier key states during mouse events? In Java for example the mouse event contains flags for modifier keys, not so in .NET.

Upvotes: 14

Views: 10319

Answers (1)

Vojislav Stojkovic
Vojislav Stojkovic

Reputation: 8153

Try using the Control.ModifierKeys property:

if ((Control.ModifierKeys & Keys.Shift) != Keys.None)
{
    // do my stuff
}

Upvotes: 22

Related Questions