Solved

trapping function keys

Posted on 2002-05-12
10
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

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 …
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

735 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