Hotkey independent of what has the control focus

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?
LVL 32
Who is Participating?
zzzzzoocConnect With a Mentor Commented:
You can use HotKey (an example of mine below):

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

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
DrDamnitAuthor Commented:
Keypreview did it!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.