Solved

trapping function keys

Posted on 2002-05-12
10
368 Views
Last Modified: 2012-06-27
Can anyone tell how i can do something when F12 key is pressed. It seems it cannot be trapped in KeyPress event like the other keys using the ASCII code. Please help
0
Comment
Question by:ahmed021399
10 Comments
 

Accepted Solution

by:
HobbitHouse earned 200 total points
ID: 7004330
put this in a text box keydown:

Private Sub txtReceiver_KeyDown(KeyCode As Integer, Shift As Integer)
    MsgBox "got key with code = " & CStr(KeyCode)
    If KeyCode = 123 Then MsgBox "what do you mean there's no F12?"
End Sub


0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7004416
The KeyPress event is only good for trapping ASCII characters (letters, numbers, punctuation, delete, enter, back, ...)
0
 
LVL 45

Expert Comment

by:aikimark
ID: 7004700
When possible, use the intrinsic constants (keycode in this case) for clearer code.  

vbKeyF12 = &h7B = 123


0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7004811
If yopu need to trap F12 key in entire form, first set Heypreview property of form to true, after that use some like this:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if KeyCode=vbkeyf12 then
  Debug.Print KeyCode
end if
End Sub
0
 
LVL 4

Expert Comment

by:Monchanger
ID: 7005448
This might be overkill, but it will capture that key you want. It's actually meant to capture keys outside (as well as inside) your application.

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=24607&lngWId=1

Since you want to use F12, I guess it wouldn't really hurt other applications.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7006006
Where you read:
"If yopu need to trap F12 key in entire form, first set Heypreview "
it must be:
"If you need to trap F12 key in entire form, first set KeyPreview "
Sorry.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 7006128
Isn't "Heypreview" a lot like Caller-ID? :-)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7006148
:))
0
 

Author Comment

by:ahmed021399
ID: 7007821
Richie your code is just for the active application, right?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7008476
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now