Systemwide Hotkeys

Creative ideas/suggestions for HMG

Moderator: Rathinagiri

Post Reply
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Systemwide Hotkeys

Post by Roberto Lopez »

Hi All,

As I've commented in another post, I'm working in an utility that sits in system tray.

The purpose of this utility is to capture hotkeys (systemwide) and paste a specific code number according key pressed.

It must work with focused edit control in any application.

To implement this, the hotkeys must be trapped even when our HMG app, is not the active one (remember, we are waiting in the system tray).

This situation remembers me a problem at the start of MiniGUI library development.

The "problem" was that hotkeys were available systemwide :)

Then, to solve this, I've filtered the WM_HOTKEY message, to ignore hotkeys when our app is not active.

So, the only thing required to have (optional) systemwide hotkeys is to create a publc flag (living at _HMG_SYSDATA) and according to it, activate or deactivate WM_HOTKEY filter.

A very easy to accomplish wish :)

Thanks for your attention.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Systemwide Hotkeys

Post by Pablo César »

Interesting Roberto ! :)
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
gfilatov
Posts: 1067
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Systemwide Hotkeys

Post by gfilatov »

Roberto Lopez wrote:Hi All,
...

So, the only thing required to have (optional) systemwide hotkeys is to create a publc flag (living at _HMG_SYSDATA) and according to it, activate or deactivate WM_HOTKEY filter.

A very easy to accomplish wish :)
Hi Roberto,

Please take a look for the following code's snippet from the Minigui Ext source:

Code: Select all

...
   CASE nMsg == WM_HOTKEY

      // Process HotKeys

      i := AScan ( _HMG_aControlIds , wParam )

      IF i > 0
         IF _HMG_aControlType [i] == "HOTKEY"
            IF _HMG_aControlParentHandles [i] == GetActiveWindow() .OR. _HMG_GlobalHotkeys == .T.
               IF _DoControlEventProcedure ( _HMG_aControlProcedures [i] , i )
                  RETURN 0
               ENDIF
            ENDIF
         ENDIF
      ENDIF
...
May be it give an idea to HMG developers :?:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Systemwide Hotkeys

Post by Roberto Lopez »

gfilatov wrote: Hi Roberto,

Please take a look for the following code's snippet from the Minigui Ext source:
<...>
Yes, of course. It's very easy.

In fact the Windows API function 'RegisterHotKey' reference, clearly states that 'Defines a system-wide hot key': http://msdn.microsoft.com/en-us/library ... s.85).aspx.

But I've selected this API function, since is extremely easier to implement than other alternatives and (at that time) that was my main development strategy :)
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Systemwide Hotkeys

Post by srvet_claudio »

Hi Roberto,
see this demo:

Code: Select all

#include "hmg.ch"

Function Main

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 500 HEIGHT 300 ;
      TITLE 'Press ALT+F9' ;
      MAIN

      ON KEY ALT+F9 ACTION MsgInfo ("HotKey Action")

   END WINDOW


   #define WM_HOTKEY      0x0312
   CREATE EVENT PROCNAME AllHotKey() MSG WM_HOTKEY
   
   Form_1.Center()
   Form_1.Activate()
Return Nil


// If the WM_HOTKEY message was generated by a system-defined hot key, wParam will be one of the following values:
#define IDHOT_SNAPWINDOW  (-1)   // The "snap desktop" hot key was pressed
#define IDHOT_SNAPDESKTOP (-2)   // The "snap window" hot key was pressed

#define MOD_ALT       1
#define MOD_CONTROL   2
#define MOD_SHIFT     4
#define MOD_WIN       8


Function AllHotKey()
LOCAL cFormName := ""
LOCAL hWnd   := EventHWND()
LOCAL wParam := EventWPARAM()
LOCAL lParam := EventLPARAM()

   GetFormNameByHandle    ( hWnd, @cFormName )
   ID     := wParam
   VK     := HIWORD (lParam)
   MOD_VK := LOWORD (lParam)

   IF MOD_VK == MOD_ALT
      MOD_VK := "ALT"
   ELSEIF MOD_VK == MOD_CONTROL
      MOD_VK := "CONTROL"
   ELSEIF MOD_VK == MOD_SHIFT
      MOD_VK := "SHIFT"
   ELSEIF MOD_VK == MOD_WIN
      MOD_VK := "WIN"
   ENDIF

   MsgInfo ({ "HotKey --> ID: ",ID ,"   FormName: "+cFormName, "   Mod: ",MOD_VK ,"   VirtualKey: ",VK })

Return NIL
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: Systemwide Hotkeys

Post by Roberto Lopez »

srvet_claudio wrote:Hi Roberto,
see this demo:
<...>
Nice!

I usually forget the CREATE EVENT command :)
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Agil Abdullah
Posts: 204
Joined: Mon Aug 25, 2014 11:57 am
Location: Jakarta, Indonesia
Contact:

Re: Systemwide Hotkeys

Post by Agil Abdullah »

Interesting. I've no idea about it before reading this topic.

Many-many thanks.
Agil Abdullah Albatati (just call me Agil)
Programmer Never Surrender
Post Reply