|
-
Aug 17th, 2012, 06:01 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Function Keys
hi friends ,in order my application more friendly and let user use keyboard instead of mouse
I used below code;
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 97 Or KeyAscii = 65 Then
Button1_Click
End If
end sub
so when user presses "a" or "A" it's like as if he has clicked on button1.this piece of code works well,now my question is how can I replace "a" with a function key as
F1 for example?it seems they dont have it (or they do??)
thank you so much
-
Aug 17th, 2012, 06:20 PM
#2
Re: Function Keys
you could use api instead
Code:
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Const VK_F1 As Long = &H70
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Debug.Print "Key F1 Pressed: " & CBool(GetAsyncKeyState(VK_F1))
End Sub
-
Aug 17th, 2012, 09:48 PM
#3
Re: Function Keys
Instead of using KeyPress use the KeyDown event to capture function key code
No need to use the API for this
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 112
MsgBox "You pressed F1"
Case 113
MsgBox "You pressed F2"
End Select
End Sub
Last edited by DataMiser; Aug 17th, 2012 at 09:51 PM.
-
Aug 18th, 2012, 04:15 AM
#4
Thread Starter
Addicted Member
-
Aug 18th, 2012, 04:17 AM
#5
Re: [RESOLVED] Function Keys
No need to use literals;
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF1
MsgBox "You pressed F1"
Case vbKeyF2
MsgBox "You pressed F2"
End Select
End Sub
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
|