Tausend Dank!
Ihr Spürsinn brachte mich auf die richtige Fährte. Mit
scheint die entscheidende Hürde überwunden zu sein (das ist anscheinend wie bei Delphi). Hoffentlich finde ich nicht noch etwas, was mich hier nach Hilfe schreien läßt.
Edit: Was mir noch nicht klar ist: Wo fügt man die Prozedur HotKeyPressed am besten ein: Direkt bei TForm noch vor private, als (nach) private oder als (nach) public? Es scheint überall zu funktionieren, doch wo ist es korrekt?
Edit 2: Noch als kleines Dankeschön hier, wie man mehr als eine Taste mit (jeweils) einem Hotkey belegt, also gleichzeitig mehr als ein Hotkey aktiv ist:
Code: Alles auswählen
unit Unit1;
{$mode objfpc}{$H+}
//{$mode Delphi}{$H+}
interface
uses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ExtCtrls, StdCtrls, ComCtrls, Menus, Windows;
type
{ TForm1 }
TForm1 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure HotKeyPressed(Key:Long_Ptr);//auf DIESE Deklaration kam es an
private
{ private declarations }
public
{ public declarations }
end;
var
Form1:TForm1;
PrevWndProc:Long_ptr;
implementation
procedure TForm1.HotKeyPressed(Key:Long_Ptr);
begin
if int(Key)=1 then showmessage('F1');
if int(Key)=2 then showmessage('F2');
end;
function MsgProc(Handle:HWnd;Msg:UInt;WParam:Windows.WParam;LParam:Windows.LParam):LResult;stdcall;
begin
if Msg=WM_HOTKEY then Form1.HotKeyPressed(Wparam);
Result:=Windows.CallWindowProc(WNDPROC(PrevWndProc),Handle,Msg,WParam,LParam)
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
PrevWndProc:=Windows.GetWindowLongPtr(Self.Handle,GWL_WNDPROC);
SetWindowLongPtr(Self.Handle,Windows.GWL_WNDPROC,Long_ptr(@MsgProc));
RegisterHotKey(Handle,1,0,VK_F1);
RegisterHotKey(Handle,2,0,VK_F2);
end;
initialization
{$I unit1.lrs}
end.