how to get Shift key status

B

Boni

Dear all,
How do I get information if Shift is pressed in a mouse wheel handler.
Thanks,
Boni
Sub MouseWheel(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) 'mouse whill handler

If SHIFT is pressed and e.delta.....

End Sub
 
?

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

Hello Boni,

You may be looking for this:

If Control.ModifierKeys = Keys.Shift Then...


Regards.


"Boni" <oilia@nospam> escribió en el mensaje | Dear all,
| How do I get information if Shift is pressed in a mouse wheel handler.
| Thanks,
| Boni
| Sub MouseWheel(ByVal sender As Object, ByVal e As
| System.Windows.Forms.MouseEventArgs) 'mouse whill handler
|
| If SHIFT is pressed and e.delta.....
|
| End Sub
|
|
 
H

Herfried K. Wagner [MVP]

José Manuel Agüero said:
You may be looking for this:

If Control.ModifierKeys = Keys.Shift Then...

.... or, if you want to get the state of the key even if other modifier keys
are pressed:

\\\
If CBool(Control.ModifierKeys And Keys.Shift) Then
...
End If
///
 
B

Boni

Thank you Jose', Herfried.
BTW, what is the difference between keys.shift and keys.shiftkey
 
?

=?Windows-1252?Q?Jos=E9_Manuel_Ag=FCero?=

Keys.Shift is a "modifier key" and Keys.ShiftKey is a "key".
You use Keys.ShiftKey when you want to check only if the shift key is pressed.
You use Keys.Shift when you are checking for another key combined with the shift and, maybe, other modifier keys.

Also, you should always use bitwise operations, as Herfried noted, combined conveniently, depending if you can or cannot ignore other modifier keys.

Regards.


"Boni" <oilia@nospam> escribió en el mensaje | Thank you Jose', Herfried.
| BTW, what is the difference between keys.shift and keys.shiftkey
| | > "José Manuel Agüero" <chema012 en hotmail.com> schrieb:
| >>You may be looking for this:
| >>
| >>If Control.ModifierKeys = Keys.Shift Then...
| >
| > ... or, if you want to get the state of the key even if other modifier
| > keys are pressed:
| >
| > \\\
| > If CBool(Control.ModifierKeys And Keys.Shift) Then
| > ...
| > End If
| > ///
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
 
H

Herfried K. Wagner [MVP]

KahurangiKea said:
Sorry, above posting is incorrect. Only returns true if Shift is only
modifier key pressed, and

dim shiftPressed as Boolean = cBool(Control.ModifierKeys = Keys.Shift)

is simpler.

Write '... = (Control.ModifierKeys = Keys.Shift)' to determine if the shift
modifier key is pressed only, and write '... = CBool(Control.ModifierKeys
And Key.Shift)' to determine if the shift modifier key and possibly other
modifier keys are pressed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top