Skip to content

How to install and use it

Uwe Rupprecht edited this page Jun 28, 2026 · 2 revisions

Install

Installing is very simple

Step 1: Download a copy of the repo Step 2: Add the "src" path to your search path in project options Step 3: Add the phk.manager and phk.general to the uses clause of your project.

Thats all. :)

Usage

As soon as you have the phk.manager in a uses of your project, there will be automatically an instance of the manager called Hotkeymanager. So you do not need to handle initializing stuff.

The first thing you need to do is, to define your Hotkeys. This can be done in 2 (or more) Steps:

New Hotkeys

The AddHotkey command of the manager is used, to define a new hotkey, together with a keystroke.

Exsample:

HotId := Hotkeymanager.AddHotkey(Ord('F'),[mkControl]);

HotId is a unique id within the list of hotkeys, and should be stored in a variable of type integer. The first parameter of the function is the virtual key code of the "normal" key, that needs to pressed for triggering an action. Allowed codes are "0"-"9","A"-"Z","Num0"-"NumDivide" and the function keys "F1"-"F24".

The second parameter is a set of so called modifier keys, that needs to be pressed together with the "normal" key. The following Keys are defined as modifier keys:

mkNone No modifier key mkLShift Left shift key mkRShift Right shift key mkShift shift key general no matter which one mkLControl Left control key mkRControl Right control key mkControl control key general no matter which one mkLAlt Left alt key mkRAlt Right alt key mkAlt alt key general no matter which one mkLWin Left windows key mkRWin Right windows key mkWin windows key general no matter which one

So in the above exsample, we define "Ctrl+F" as keystroke for our hotkey.

Attention

Its up to you, to avoid collision on hotkeys. Some hotkeys are defined by windows itself ("Ctrl+C"), but also your own hotkeys should not be defined twice. This can lead to unexpected behaviors.

If you want to add another key stroke to your hotkey, you can use the AddKeyStroke function. The first parameter of this function is the HotId (the return value of the AddHotKey function). The second and third parameter are the same as the parameter on AddHotkey.

Exsample: var HotId: integer begin HotId := Hotkeymanager.AddHotkey(Ord('F'),[mkControl]); HotKeymanager.AddKeyStroke(HotId,Ord('S'),[]); end; This defines "Ctrl+F" as initial keystroke. Followed by "S" the action of the hotkey will be triggert.

This way, you can define very complex keystrokes for a hot key. The last key stroke will be always the one, that triggers the action.

Commands

So we know now, how to define the keystrokes, we now want to do something, when the key(s) are pressed. This is the time, when commands come into play.

Simple said, commands are the action, that runs, when a hotkey is triggert.

There are currently 3 types of commands, that can be used

Event-Command

This works like a normal event on delphi. To add a event command to a HotKey use AddHotKeyEvent function:

'Hotkeymanager.AddHotKeyEvent(HotId,MyProc);'

MyProc needs to be of type TNotifyCommand, which is defined as

TNotifyCommand = Procedure (Sender:TObject) of Object

Action-Command

With this, you can use a Action as command. To do so, use:

'Hotkeymanager.AddHotKeyAction(HotId,MyAction)'

where MyAction is of type TBasicAction.

Message-Command

This kind of command, sends a WM_PHKHOTKEY to a specified window. The window needs to handle the message, and performs a action on this.

To Defines this, use :

Hotkeymanager.AddHotKeyMessage(HotId,MyWindow) where MyWindow is a HWND.

As you can add as many commands as you like, it's possible to use this mechanism as a kind of macro system also.

Starting System

Now, that we defined all our hotkeys, we need to tell the manager, that he now can handle keystrokes.

This can be done using the start function.

Hotkeymanager.start();

The manager know listen to keystrokes, checks wether the stroke matches one of the keystrokes for our hotkeys, and if it matches, trigger the commands.

The function takes an optional parameter "Mode", which can be one of the following values:

hmLocal Only keystrokes, that are send to your application, are taken into account. Other keystrokes are ignored. This is the default value.

hmGlobal Every keystroke, that windows got, are taken into account. This way, you can react on keystrokes even before windows itself handles them. But be aware, that comes with the cost of resources and time. It can slow down (or even lock) your whole computer.

Other functions

There are some other functions, that you might want to use, depending on your needs.

DisableHotKey

Hotkeymanager.DisableHotKey(HotId,<Boolean>);

With this function, you can disable/enable a hotkey dynamically. True means that the hotkey should be disabled.

RemoveHotkey

HotKeymanager.RemoveHotkey(HotId);

Removes a Hotkey from the list of hotkeys. Returns true on success.

IsListening

HotKeymanager.isListening<Boolean>

Returns true, if the Hotkeymanager is listening to keystrokes.

Stop

HotKeymanager.stop;

Stops the Hotkeymanager from listening to keystrokes. Could be helpfull, if your application does critical stuff, and should be not disturbed by a hotkey. Use the start function to tell the Hotkeymanager to listen again.