...die THotKey Komponente verwenden, um einen globalen Hotkey zu registrieren?
Autor: Thomas Stutz
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, Menus;
type
TForm1 = class(TForm)
HotKey1: THotKey;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
Hotkey_id : Integer;
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
// WM_HOTKEY Hotkey Handler
procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
if Msg.HotKey = Hotkey_id then
ShowMessage('Hotkey empfangen');
end;
// Transform TShortCut to use for RegisterHotKey
// TShortCut für RegisterHotKey umwandeln
procedure ShortCutToHotKey(HotKey: TShortCut; var Key : Word; var Modifiers: Uint);
var
Shift: TShiftState;
begin
ShortCutToKey(HotKey, Key, Shift);
Modifiers := 0;
if (ssShift in Shift) then
Modifiers := Modifiers or MOD_SHIFT;
if (ssAlt in Shift) then
Modifiers := Modifiers or MOD_ALT;
if (ssCtrl in Shift) then
Modifiers := Modifiers or MOD_CONTROL;
end;
// Register Hotkey
// Hotkey registrieren
procedure TForm1.Button1Click(Sender: TObject);
var
Key : Word;
Modifiers: UINT;
begin
ShortCutToHotKey(HotKey1.HotKey, Key, Modifiers);
Hotkey_id := GlobalAddAtom('MyHotKey_1');
RegisterHotKey(Handle, Hotkey_id, Modifiers, Key);
end;
// Remove Hotkey
// Hotkey entfernen
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnRegisterHotKey(Handle, Hotkey_id);
GlobalDeleteAtom(Hotkey_id);
end;
printed from
www.swissdelphicenter.ch
developers knowledge base