Global Hot-Key

Hello,

Is it possible in Visual Basic 6.0 to program a global hot-key?  For example, could I cause CTL/M to trigger a certain function no matter where I am in the program?
LVL 1
NigelRocksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NigelRocksAuthor Commented:
Quick follow-up question:

Where do I trap the windows messages once the keys are registered?  The code in that article doesn't seem to do the trick.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
The sub that fires is CallbackMsgs() in the MODULE.  It works fine for me...

Give more details about your setup and I can help you troubleshoot it.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

NigelRocksAuthor Commented:
If you're still there, the problem seems to be that wmsg does not match WM_HOTKEY so it never gets in.  When I took that if condition out, I had all kinds of things blow up.
Public Function CallbackMsgs(ByVal wHwnd As Long, ByVal wmsg As Long, ByVal wp_id As Long, ByVal lp_id As Long) As Long
    If wmsg = WM_HOTKEY Then
        Call DoFunctions(wp_id)
        CallbackMsgs = 1
        Exit Function
    End If
    CallbackMsgs = CallWindowProc(mnReturnWindow, wHwnd, wmsg, wp_id, lp_id)
End Function

Open in new window

0
Mike TomlinsonMiddle School Assistant TeacherCommented:
It will only be WM_HOTKEY if you have successfully registered a HotKey combination for your app using the RegisterHotKey() API:

    retVal0 = RegisterHotKey(Me.hwnd, 0, MOD_CTRL, VK_F10)
0
NigelRocksAuthor Commented:
Here's my RegisterHotKeys sub.  Is there something wrong with it?
Public Sub RegisterHotKeys(thisForm As Form)
    
    Dim bDummyVariable As Boolean
    
    Set mfActiveHotkeyForm = thisForm
    
    Select Case mfActiveHotkeyForm.Name
 
        Case "frmGlobalSearch"
        
            bDummyVariable = RegisterHotKey(thisForm.hwnd, 0, MOD_CTRL, VK_F10)
            bDummyVariable = RegisterHotKey(thisForm.hwnd, 1, MOD_CTRL, VK_F11)
            bDummyVariable = RegisterHotKey(thisForm.hwnd, 2, MOD_CTRL, VK_F12)
    
 
    
    ' Subclassing the form to get the Windows callback msgs.
    mnReturnWindow = SetWindowLong(thisForm.hwnd, GWL_WNDPROC, AddressOf CallbackMsgs)
    
    End Select
End Sub

Open in new window

0
Mike TomlinsonMiddle School Assistant TeacherCommented:
What is being returned by RegisterHotKey()?

Try this:

            bDummyVariable = RegisterHotKey(thisForm.hwnd, 0, MOD_CTRL, VK_F10)
            Debug.Print "Ctrl-F10 = " & bDummyVariable
            bDummyVariable = RegisterHotKey(thisForm.hwnd, 1, MOD_CTRL, VK_F11)
            Debug.Print "Ctrl-F11 = " & bDummyVariable
            bDummyVariable = RegisterHotKey(thisForm.hwnd, 2, MOD_CTRL, VK_F12)
            Debug.Print "Ctrl-F12 = " & bDummyVariable
0
NigelRocksAuthor Commented:
I'm getting "True" back every time I call RegisterHotKey.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
I would need to see all of your code to get a better idea of what is going on...I recommend you open a new question and post your code so you can get help from others besides just me.  =)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.