Trapping for Ctrl or Alt Key?

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.
 
S

Stuart McCall

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.
 
P

Phil Reynolds

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.
 

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

Similar Threads


Top