Trapping for Ctrl or Alt Key?

  • Thread starter Thread starter Phil Reynolds
  • Start date Start date
P

Phil Reynolds

Is there a way to trap for a Ctrl or Alt key when typing in a field? I want
to be able to perform an action when the user types Ctl+A or Alt+A or
whatever. I noticed the KeyDown function allows you to check for the state
of the Shift key. I'm looking for something like that for Ctrl and/or Alt.
Thank you.
 
Phil Reynolds said:
Is there a way to trap for a Ctrl or Alt key when typing in a field? I
want to be able to perform an action when the user types Ctl+A or Alt+A or
whatever. I noticed the KeyDown function allows you to check for the state
of the Shift key. I'm looking for something like that for Ctrl and/or Alt.
Thank you.

In the OnKeyDown event proc:

Dim intCtrlDown As Integer

intCtrlDown = (Shift And acCtrlMask) > 0
If intCtrlDown And KeyCode = vbKeyA Then
MsgBox "Ctrl-A was pressed"
End If

You also have constants for the other shift keys:

acAltMask
scShiftMask

To obtain KeyCode constants, search for 'keycode' in the object browser.
 
Cool. Thanks!

Stuart McCall said:
In the OnKeyDown event proc:

Dim intCtrlDown As Integer

intCtrlDown = (Shift And acCtrlMask) > 0
If intCtrlDown And KeyCode = vbKeyA Then
MsgBox "Ctrl-A was pressed"
End If

You also have constants for the other shift keys:

acAltMask
scShiftMask

To obtain KeyCode constants, search for 'keycode' in the object browser.
 
Back
Top