Solved

Hotkey independent of what has the control focus

Posted on 2004-08-04
3
270 Views
Last Modified: 2010-05-18
I need to know how to have a hot key execute a sub routine or function regardless of what control has the focus. Functionally, what I want is very similar to when you assign CTRL-N to a menu.

The software is a point of sale system, and I need the user to be able to press "c" and have the credit card dialog pop up, or the "t" key and have the "tender bill" dialog come up.

Any thoughts?
0
Comment
Question by:DrDamnit
3 Comments
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 500 total points
Comment Utility
You can use HotKey (an example of mine below):
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_21047290.html

..or just do it through form-level. A form's KeyPreview property allows keydown events to be passed to the form even if another control has focus.

Example:
-------------
Option Explicit
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF1 Then
        Call MsgBox("F1 was pressed.")
    End If
End Sub
Private Sub Form_Load()
    Me.KeyPreview = True
End Sub
0
 
LVL 5

Expert Comment

by:cristy56
Comment Utility
0
 
LVL 32

Author Comment

by:DrDamnit
Comment Utility
Keypreview did it!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

744 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

16 Experts available now in Live!

Get 1:1 Help Now