Solved

trapping function keys

Posted on 2002-05-12
10
391 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 70

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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

839 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