how to capture multiple key strokes at once (1 Viewer)

dreamdelerium

Registered User.
Local time
Today, 12:33
Joined
Aug 24, 2007
Messages
88
anyone know a way to capture multiple key strokes when a form is open? when a form is open and the user presses a combination of keys at the same time (ie cntrl+j) i want an event to fire. (much like when you hit cntrl+alt+del in windows)

microsoft access 2003
 
- Make sure the KeyPreview property of the form is True, otherwise keystrokes are handled by the focussed control and key events are never raised for the form.
- Then handle the Form_KeyDown and/or Form_KeyPress events.
- You could perhaps store a key stroke history in an array, and for each key event shift the items in the array and scan for patterns.
- One of those events also returns whether Shift/Ctrl/Alt were pressed in combination with other keys.
- Also, check out the VBA.KeyCodeConstants module, which provides named constant for each key, like vbKeyControl and vbKeyPageDown, etc...
 
woot

well, finally got it:
the keydown event for the form:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
HandleKeys KeyCode, Shift
End Sub

call this function:

Code:
Public Sub HandleKeys(KeyCode As Integer, Shift As Integer)
Dim ShiftDown As Integer
Const KEY_j = 74
Const CTRL_MASK = 2
ShiftDown = ((Shift And CTRL_MASK) > 0)
Select Case KeyCode
Case KEY_j
If ShiftDown = -1 Then
'do what ever here
Else
End If
End Select
KeyCode = 0
End Sub
 

Users who are viewing this thread

Back
Top Bottom