|
-
Sep 24th, 2001, 09:02 AM
#1
Thread Starter
Lively Member
Simple question...to which I don't know the anwser!
How can I create an event procedure that responds to a particular key press? For example, exit the program when the escape key is pressed?
Also, following on from that how to set up procedure that are activated when for example, ctrl+shift+S is pressed?
Thanks Darren.
-
Sep 24th, 2001, 09:09 AM
#2
Retired VBF Adm1nistrator
First Question :
VB Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then End
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Sep 24th, 2001, 09:10 AM
#3
There is a couple of ways on how you can do this.
The first is to create a menu and asign the shortcut keys to that menu item. The click event for the menu item will then be raised when the shortcut is pressed.
The other way is to use the KeyDown event of the form (you must set the KeyPreview property to True for this to work) and check what key combination that have been pressed in that event and then call any procedure you like.
VB Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'the KeyPreview property of the form must be set to True
'this property can be set during design-time
Select Case KeyCode
Case vbKeyEscape
Unload Me
Case vbKeyS
If (KeyCode And vbShiftMask) = vbShiftMask And (KeyCode And vbCtrlMask) = vbCtrlMask Then
MsgBox "Ctrl+Shift+S have been pressed", vbInformation
End If
End Select
End Sub
Best regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|