Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 715
Viesturs Avatar asked Feb 05 '09 09:02

Viesturs


People also ask

How do I know if shiftKey is pressed?

The mouseEvent shiftKey property is used to define whether the shift key is pressed or not. It is a boolean value. When the shift key is pressed then on click of the mouse left button, it returns true and if the shift key is not pressed then it returns false.

What is shiftKey in javascript?

Definition and Usage. The shiftKey property returns a Boolean value that indicates whether or not the "SHIFT" key was pressed when a key event was triggered. Note: This property is read-only.


1 Answers

Try using the Control.ModifierKeys property:

if ((Control.ModifierKeys & Keys.Shift) != Keys.None)
{
    // do my stuff
}
like image 170
Vojislav Stojkovic Avatar answered Sep 24 '22 19:09

Vojislav Stojkovic