Groups | Blog | Home
all groups > vb.net > october 2005 >

vb.net : how to get Shift key status


Boni
10/31/2005 8:00:43 PM
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

José_Manuel_Agüero
10/31/2005 9:09:52 PM
Hello Boni,

You may be looking for this:

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


Regards.


"Boni" <oilia@nospam> escribi=F3 en el mensaje =
news:OnBzm1k3FHA.3636@TK2MSFTNGP09.phx.gbl...
| 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=20
| System.Windows.Forms.MouseEventArgs) 'mouse whill handler
|=20
| If SHIFT is pressed and e.delta.....
|=20
| End Sub
|=20
Herfried K. Wagner [MVP]
10/31/2005 9:55:08 PM
"José Manuel Agüero" <chema012 en hotmail.com> schrieb:
[quoted text, click to view]

.... 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/>
Boni
10/31/2005 10:08:03 PM
Thank you Jose', Herfried.
BTW, what is the difference between keys.shift and keys.shiftkey
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb im Newsbeitrag
news:eWOJi1l3FHA.632@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

José_Manuel_Agüero
11/1/2005 7:47:12 PM
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=F3 en el mensaje =
news:uru8y8l3FHA.3000@TK2MSFTNGP12.phx.gbl...
| Thank you Jose', Herfried.
| BTW, what is the difference between keys.shift and keys.shiftkey
| "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb im =
Newsbeitrag=20
| news:eWOJi1l3FHA.632@TK2MSFTNGP10.phx.gbl...
| > "Jos=E9 Manuel Ag=FCero" <chema012 en hotmail.com> schrieb:
| >>You may be looking for this:
| >>
| >>If Control.ModifierKeys =3D Keys.Shift Then...
| >
| > ... or, if you want to get the state of the key even if other =
modifier=20
| > keys are pressed:
| >
| > \\\
| > If CBool(Control.ModifierKeys And Keys.Shift) Then
| > ...
| > End If
| > ///
| >
| > --=20
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>=20
|=20
KahurangiKea
7/20/2007 8:08:13 PM
Dim shiftPressed as Boolean = (Control.ModifierKeys And Keys.Shift) = Keys.Shift

Determines whether shift key is pressed, regardless of whether other keys are pressed. Brackets are necessary.

From http://developmentnow.com/g/38_2005_10_0_0_628353/how-to-get-Shift-key-status.htm

Posted via DevelopmentNow.com Groups
KahurangiKea
7/20/2007 8:22:25 PM
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.

From http://developmentnow.com/g/38_2005_10_0_0_628353/how-to-get-Shift-key-status.htm

Posted via DevelopmentNow.com Groups
Herfried K. Wagner [MVP]
7/21/2007 4:56:52 PM
"KahurangiKea" <nospam@developmentnow.com> schrieb:
[quoted text, click to view]

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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
AddThis Social Bookmark Button