Solved

trapping function keys

Posted on 2002-05-12
10
406 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

717 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