Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Key Down, Key Up Or Key Press?

Status
Not open for further replies.

scrano

Technical User
Jan 24, 2001
51
0
0
AU
I want to use three a press of three keys. These would be the control, alt and f1 keys to close a form. Can anyone tell me how to do this and what key event I need to set it on? Can anyone also please tell me if the event that it's set on varys depending on the keys pressed? Thanks.
 
Hi, I would use the keyup event - you will also need to turn the form property 'Key Preview' to yes (this means that the form will see the key combination before the control. the code would look something like...
Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim ShiftDown As Integer
Dim CtrlDown As Integer

If KeyCode = vbKeyEnd Then    '[COLOR=green] test key character used, could also do soemthing like Char(Keycode) = "A"[/color]
    
    ShiftDown = (Shift And acShiftMask) > 0    [COLOR=green]' test for shift down[/color]
    CtrlDown = (Shift And acCtrlMask) > 0    [COLOR=green] test for ctrl down[/color]
    
    If ShiftDown And CtrlDown Then    [COLOR=green] ctrl and shift down[/color]
        [COLOR=green]' do stuff here...[/color]
    end if
End If

End Sub

HTH, Jamie
FAQ219-2884
[deejay]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top