?
Solved

Global Hot-Key

Posted on 2008-02-01
9
Medium Priority
?
680 Views
Last Modified: 2008-04-15
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?
0
Comment
Question by:NigelRocks
  • 5
  • 4
9 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 20804714
0
 
LVL 1

Author Comment

by:NigelRocks
ID: 21074042
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 21074619
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 1

Author Comment

by:NigelRocks
ID: 21361885
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 21362029
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
 
LVL 1

Author Comment

by:NigelRocks
ID: 21362122
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 21362343
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
 
LVL 1

Author Comment

by:NigelRocks
ID: 21362436
I'm getting "True" back every time I call RegisterHotKey.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 21362478
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

601 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