473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Control, Shift, Alt Status

How do you check if the Control, Shift or Alt key is pressed at any given
time (not necessarily in a keyevent)?

Cheers,
Johnny J.
Sep 3 '07 #1
4 4852
Johnny J. wrote:
How do you check if the Control, Shift or Alt key is pressed at any
given time (not necessarily in a keyevent)?
You can use the Windows.Forms.Control.ModifierKeys property:

\\\
If (Windows.Forms.Control.ModifierKeys And Keys.Control) <0 Then
Debug.WriteLine("Ctrl is pressed")
End If
If (Windows.Forms.Control.ModifierKeys And Keys.Shift) <0 Then
Debug.WriteLine("Shift is pressed")
End If
If (Windows.Forms.Control.ModifierKeys And Keys.Alt) <0 Then
Debug.WriteLine("Alt is pressed")
End If
///

HTH,

--

(O)enone
Sep 3 '07 #2
Thanks a lot - that solved my problem

Cheers,
Johnny J.


"(O)enone" <oe****@nowhere.comwrote in message
news:eM**************@TK2MSFTNGP03.phx.gbl...
Johnny J. wrote:
>How do you check if the Control, Shift or Alt key is pressed at any
given time (not necessarily in a keyevent)?

You can use the Windows.Forms.Control.ModifierKeys property:

\\\
If (Windows.Forms.Control.ModifierKeys And Keys.Control) <0 Then
Debug.WriteLine("Ctrl is pressed")
End If
If (Windows.Forms.Control.ModifierKeys And Keys.Shift) <0 Then
Debug.WriteLine("Shift is pressed")
End If
If (Windows.Forms.Control.ModifierKeys And Keys.Alt) <0 Then
Debug.WriteLine("Alt is pressed")
End If
///

HTH,

--

(O)enone

Sep 3 '07 #3
On 3 Sep, 13:19, "Johnny J." <j...@altcom.sewrote:
How do you check if the Control, Shift or Alt key is pressed at any given
time (not necessarily in a keyevent)?

Cheers,
Johnny J.
If (My.Computer.Keyboard.AltKeyDown) Then

or

If (My.Computer.Keyboard.CtrlKeyDown) Then

or

If (My.Computer.Keyboard.ShiftKeyDown) Then

Phillip Taylor

Sep 3 '07 #4
Thanks Philip :-)

/Johnny J.
"Phillip Taylor" <Ph*****************@gmail.comskrev i meddelandet
news:11*********************@22g2000hsm.googlegrou ps.com...
On 3 Sep, 13:19, "Johnny J." <j...@altcom.sewrote:
>How do you check if the Control, Shift or Alt key is pressed at any given
time (not necessarily in a keyevent)?

Cheers,
Johnny J.

If (My.Computer.Keyboard.AltKeyDown) Then

or

If (My.Computer.Keyboard.CtrlKeyDown) Then

or

If (My.Computer.Keyboard.ShiftKeyDown) Then

Phillip Taylor

Sep 3 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Paul Cooper | last post by:
Dear All, I am working on a piece of Javascript code that needs to detect a mouse-click, shift-click and control-click. The code is not my own - it is a part of a much larger suite of routines....
4
by: Vazz | last post by:
I am trying to capture the key combination "Control + Shift + Enter" in a KeyDown event. I am able capture "Control + Enter" using (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control). How do I...
2
by: phil cunningham | last post by:
How do I detect if the user is holding down a SHIFT or CONTROL key whilst moving the mouse. Sorry for the trivial question but I'm just getting started with this Phil
6
by: Barguast | last post by:
When a control's 'Click' event is triggered, is there a way I can test whether the CTRL / Alt / Shift keys are pressed as well? I've thought about capturing KeyDown events before the click but this...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
5
by: Colin Graham | last post by:
I am using the following code on my form to capture whether the tab control has been pressed. Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData...
2
by: Steph. | last post by:
Hi, A simple question : How can I detect if the CTRL key is pressed when User click on a control ? Thanks, Steph.
7
by: Csaba Gabor | last post by:
I'd like to detect the shift key when a button is "clicked" in Firefox/Mozilla. If the button is clicked with the mouse, no problem. However, if the onclick event is keyboard originated, then my...
2
by: Charles Law | last post by:
I'll kick myself when you tell me, but ... I have a user control on a form, and I want the user control to see the arrow keys when I press them. If I press just about any other key the control's...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.