unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
HkI=Record
Key:tShortcut;
Modify:Cardinal;
Interval:Word;
Notify:
String;
end ;
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
procedure MyWindowProc(
var Message:TMessage);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
HotKeys:
array[0..2]
of HKI;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.MyWindowProc(
var Message: TMessage);
var notify:
string;
begin
notify:='
';
if Message.Msg=WM_Hotkey
Then begin
SetTimer(Self.Handle,
Message.WParam,Hotkeys[
Message.WParam-$BFF0].Interval*1000,
nil);
SendMessage(GetActiveWindow,WM_KEYDOWN,Hotkeys[
Message.WParam-$BFF0].Modify,Hotkeys[
Message.WParam-$BFF0].Key);
SendMessage(GetActiveWindow,WM_KEYUP,Hotkeys[
Message.WParam-$BFF0].Modify,Hotkeys[
Message.WParam-$BFF0].Key);
notify:='
';
end
else if Message.Msg=WM_TIMER
Then Begin
if HotKeys[
Message.WParam-$BFF0].Notify<>'
'
Then
begin
notify:='
';
notify:=HotKeys[
Message.WParam-$BFF0].Notify;
end;
KillTimer(Self.Handle,
Message.WParam);
end
else WndProc(
Message);
if sametext(notify,'
bla')
then
Showmessage('
Taste gedrückt');
notify:='
';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
WindowProc:=MyWindowProc;
Hotkeys[0].Key:=Lo(97);
// Ascii Code der zu drueckenden taste, bsp 'a'
Hotkeys[0].Modify:=0;
inc(Hotkeys[0].Modify,MOD_CONTROL);
// Ob Shift , Alt, STRG gedrueckt sein soll
Hotkeys[0].Notify:='
bla';
// die msg, die beim tastendruck uebergeben wird
RegisterHotKey(Self.Handle,$BFF0+0,Hotkeys[0].Modify,Hotkeys[0].Key);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnregisterHotKey(Self.Handle,$BFF0+0);
end;
end.