User Tools

Site Tools


responding_20to_20a_20hot_20key

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

responding_20to_20a_20hot_20key [2018/03/31 13:19]
127.0.0.1 external edit
responding_20to_20a_20hot_20key [2018/04/15 11:08] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Responding to a hot key===== =====Responding to a hot key=====
  
-//by Richard Russell, October 2010//\\ \\  A **hot key** is a unique system-wide key combination which can be used to cause your program to take some action, irrespective of which application currently has the keyboard 'input focus'​. Typically your program will be running invisibly 'in the background',​ biding its time until the appropriate keys are pressed.\\ \\  The code listed below is a '​template'​ program which simply registers the associated hot key, and prints a message when it is detected. You should be able to expand it to perform any action(s) you wish.\\ \\  Obviously, any particular hot key combination must be unique. Windows uses a first-come-first-served method; whichever program first registers a particular key combination will succeed, and subsequent programs which attempt to register that same combination will fail to do so. Try to choose an unusual key combination (the template program below uses **Alt+ScrollLock**).\\ \\  If your program needs to respond to two or more different hot key combinations,​ you can specify different IDs; the ID is received in the **@wparam%** parameter of the WM_HOTKEY messages. The program below uses only one hot key, so does not bother to check the ID.\\ \\  Most commonly you will want to compile your program with the '​Initial window state' set to **hidden**, and you may wish to start your program automatically by placing the executable in the **Start Up** folder, or creating an appropriate registry entry.\\ +//by Richard Russell, October 2010//\\ \\  A **hot key** is a unique system-wide key combination which can be used to cause your program to take some action, irrespective of which application currently has the keyboard 'input focus'​. Typically your program will be running invisibly 'in the background',​ biding its time until the appropriate keys are pressed.\\ \\  The code listed below is a '​template'​ program which simply registers the associated hot key, and prints a message when it is detected. You should be able to expand it to perform any action(s) you wish.\\ \\  Obviously, any particular hot key combination must be unique. Windows uses a first-come-first-served method; whichever program first registers a particular key combination will succeed, and subsequent programs which attempt to register that same combination will fail to do so. Try to choose an unusual key combination (the template program below uses **Alt+ScrollLock**).\\ \\  If your program needs to respond to two or more different hot key combinations,​ you can specify different IDs; the ID is received in the **@wparam%** parameter of the WM_HOTKEY messages. The program below uses only one hot key, so does not bother to check the ID.\\ \\  Most commonly you will want to compile your program with the '​Initial window state' set to **hidden**, and you may wish to start your program automatically by placing the executable in the **Start Up** folder, or creating an appropriate registry entry. 
 + 
 +<code bb4w> ​
         _MOD_ALT = &1         _MOD_ALT = &1
         WM_HOTKEY = &312         WM_HOTKEY = &312
Line 45: Line 47:
         SYS "​SendMessage",​ @hwnd%, 0, 0, 0         SYS "​SendMessage",​ @hwnd%, 0, 0, 0
         = T%         = T%
 +</​code>​
 +
 Obviously if your program needs to respond to other **ON SYS** events it must check the appropriate **@msg%** value in **PROCsys** and act accordingly. Obviously if your program needs to respond to other **ON SYS** events it must check the appropriate **@msg%** value in **PROCsys** and act accordingly.
responding_20to_20a_20hot_20key.txt · Last modified: 2018/04/15 11:08 by richardrussell