I need to capture when the user hits ESC. I don't know the ASCII Character Code for it and I'm not sure whether I can capture it like all the other keys or whether I need to use an API.
Printable View
I need to capture when the user hits ESC. I don't know the ASCII Character Code for it and I'm not sure whether I can capture it like all the other keys or whether I need to use an API.
The keycode is vbKeyEscape and I believe its value is 27. You can capture this key.
In the keypress event it would look like if keyascii = vbkeyescape then whatever
For a command button you just need to set the cancel propery to true.
Hope this helps!
set the form's keypreview property to true
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
MsgBox "Escape"
End If
End Sub
the keycode for esc is 27
thanks, key code 27 is what I needed.