[Lazarus] HotKey with Carbon
Eugen Bolz
info at eugen-bolz.de
Thu Nov 4 20:34:19 CET 2010
Hey,
i tried to port this
http://dbachrach.com/blog/2005/11/program-global-hotkeys-in-cocoa-easily/
.
Nothing Happens If I press Option + 1.
Here's my code, I hope anybody can help me with this :) :
{ Based on
http://dbachrach.com/blog/2005/11/program-global-hotkeys-in-cocoa-easily/ }
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
StdCtrls,
MacOSAll;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
gMyHotKeyRef : EventHotKeyRef;
gMyHotKeyID : EventHotKeyID;
implementation
uses
LCLType, CarbonUtils, CarbonDef, CarbonProc;
{$R *.lfm}
function MAC_OS_Handler(ANextHandler: EventHandlerCallRef;
AEvent: EventRef;
inUserData: UnivPtr ): OSStatus; {$IFDEF darwin}mwpascal;{$ENDIF}
begin
ShowMessage('hot'); // No Message :(
Result := CallNextEventHandler(ANextHandler, AEvent);
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
eventType : EventTypeSpec;
begin
eventType.eventClass:= kEventClassKeyboard;
eventType.eventKind:= kEventHotKeyPressed;
Assert(InstallApplicationEventHandler(@MAC_OS_Handler, 1,
@eventType, nil, nil), 'Install'); // No Error
gMyHotKeyID.signature:=MakeFourCC('htk1');
gMyHotKeyID.id:=1;
OSError(
RegisterEventHotKey(49, optionKey, gMyHotKeyID,
GetApplicationEventTarget(), 0, gMyHotKeyRef),
'Register' ,''); // No Error
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UnregisterEventHotKey(gMyHotKeyRef);
end;
end.
More information about the Lazarus
mailing list