Capture multiple key presses at once

dreamdelerium

Registered User.
Local time
Today, 11:37
Joined
Aug 24, 2007
Messages
88
im trying to capture all key press and multiple key presses for a form
(ie. cntrl + f) and assign my own action to it. i want to be able to prevent all office actions from occuring (for instance if you press ctlr+f the windows "find and replace" dialog pops. i want to stop this action and assign my own). can this be done, if so how?

thanks
 
You can turn KeyPreview on at the form level and catch this sequence in the KeyDown event.
 
i think im missing something

i must be missing somethings. ive tried that, for most key presses i can capture the event but some event (like alt+f11 and cntl+f) are not captured. i set keypreview to on and selects the keypress event
 
I believe you will need to be in the KeyDown event rather than the KeyPress event.
 
Here's how you do it, with KeyPreview Property set to Yes.:

Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim intCtrlDown As Integer

intCtrlDown = (Shift And acCtrlMask) > 0

If intCtrlDown And KeyCode = vbKeyA Then
   MsgBox "Ctrl-A was pressed"
End If
End Sub

The constants for the Alternate key is acAltMask.

Just replace the acAltMask line with whatever action you want carried out.
 

Users who are viewing this thread

Back
Top Bottom