unit Shortcuts;
...
...
procedure ShortCut_SetupHotkey(Sender: TObject);
function SetHotkey(aHandle:THandle; HotkeyID:cardinal; Shortcut:TShortcut; AutoRegister:boolean=true):boolean;
procedure ShortCut_WMHotkey(
var msg: TWMHotkey) ;
procedure ShortCut_Unregister;
...
...
const
Hotkey_ID1 = 1;
Hotkey_ID2 = 2;
Hotkey_ID3 = 3;
...
...
procedure ShortCut_SetupHotkey(Sender: TObject);
begin
SetHotkey(Form1.Handle,1,ShortCut_1);
SetHotkey(Form1.Handle,2,ShortCut_2);
SetHotkey(Form1.Handle,3,ShortCut_3);
end;
// Hotkey registrieren
function SetHotkey(aHandle:THandle; HotkeyID:cardinal; Shortcut:TShortcut; AutoRegister:boolean=true):boolean;
var
Key: Word;
Shift:TShiftstate;
Modifiers:integer;
begin
result:=false;
if Shortcut = 0
then exit;
Modifiers:=0;
Unregisterhotkey(aHandle,HotkeyID);
ShortCutToKey(ShortCut, Key, Shift);
// unit Menus;
if ssCtrl
in Shift
then Modifiers:=MOD_CONTROL;
if ssAlt
in Shift
then Modifiers:=Modifiers
or MOD_ALT;
if ssShift
in Shift
then Modifiers:=Modifiers
or MOD_SHIFT;
if AutoRegister
then
result:=RegisterHotKey(aHandle, HotkeyID, Modifiers, Key)
else result:=true;
end;
procedure ShortCut_WMHotkey(
var msg: TWMHotkey ) ;
begin
if msg.HotKey = Hotkey_ID1
then
begin
//do something
end;
if msg.HotKey = Hotkey_ID2
then
begin
//do something
end;
if msg.HotKey = Hotkey_ID3
then
begin
//do something
end;
end;
procedure ShortCut_Unregister;
begin
UnregisterHotkey(Form1.handle,Hotkey_ID1);
UnregisterHotkey(Form1.handle,Hotkey_ID2);
UnregisterHotkey(Form1.handle,Hotkey_ID3);
end;