About   -   Contact   -   Purchase   -   Search   -   What's New

Hot Key Notification
Adding a Hot Key to your application will allow users to press the hotkey to activate your application. I used this API call to allow users to press Control Alt P to access my PBPaste utility that normally sits in the system tray. This allows keyboard savvy users to press the hotkey to see the PBPaste menu and paste code and headers into their application.

Firstly you will need to define the following API function as a local external:

function long SendMessageA( long lhWnd, uint uiMsg, &
	long lwMsg, long lwParam ) library 'user32'

The next thing you will need to do is to define some constants from the operating system headers files. These constants will need to be changed based on the hot key you want to use. I will explain how to calculate your constant later in the article. Define these instance variables:

Constant Long WM_SETHOTKEY = 50
Constant Long HK_MYHOTKEY = 1616 // change for your own key
Constant Long SC_HOTKEY = 61776

The variable HK_MYHOTKEY will need to be changed to specify the hot key you want to use. To calculate this you need to know a little bit about binary/hex/bytes. Basically the number is made up of two bytes, the low byte contains the ASCII key you want to use and the high byte contains the keyboard modifiers such as Control, Alt, Shift etc.

An example will probably help you here, in my example I used Control Alt P, so the ASCII code for P is 80, (A = 65) + 15 letters to get to P (Z = 90). This value needs to be in the first byte so I converted the number to Hex and got 50. Next I needed to tell windows I want Control Alt as well as P. The modifier keys are defined as follows:

  • Shift = 1
  • Control = 2
  • Alt = 4
  • Extended = 8

For those people who know binary you can see that these numbers set a bit within the high word. So to tell windows you want Control and Alt you add the two numbers together giving 6, which in hex is still 6. So I concatenated (not added) the two numbers together giving a hex value of 650 and converted this to decimal which gave me my 1616 value. By following these rules you can get any combination you choose.

Next you need to tell windows about you hotkey which is done by adding the following code to the open event of the window:

ll_RC = SendMessageA( Handle( this ), &
// Testing (ll_RC = 1) would be a good idea!

Then in the other event of your window add the following code:

	// Do your code

This will trap any hot key notifications from windows so you can do your code inside the IF, I would recommend calling a function or triggering an event, because the other event is constantly being called you want the minimum of code in here (so don't define variable or stuff!)


Top of Page

Legal Notice

Ken Howe 2011