2

I have done quite a bit of searching in Google and though I can find the switches to do this for Windows using WM_HOTKEY I cannot find it for Linux.

WM_HOTKEY Hook

uses ...,windows;

var
  PrevWndProc: WNDPROC;
const
  MY_ID=1;

function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LRESULT; stdcall;
begin
  if (uMsg=WM_HOTKEY) and (WParam=MY_ID) then
    begin
      Application.Restore;
    end;
  result:=CallWindowProc(PrevWndProc,Ahwnd, uMsg, WParam, LParam);
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  PrevWndProc:=Windows.WNDPROC(SetWindowLong(Self.Handle,GWL_WNDPROC,PtrInt(@WndCallback)));
  RegisterHotKey(Self.Handle,MY_ID,0,vk_F9);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotkey(Self.Handle,MY_ID);
end;

I am looking to place a system wide hotkey hook in XFCE4 and/or XWindows on a linux machine. I know it is possible as many screenshot programs do this all the time no matter what the Window Manager is.

I need for my app to be able to hook a key combo to activate something inside the app but I cannot find anything for this with Lazarus/Pascal on linux anywhere.

jfreak53
  • 2,239
  • 7
  • 37
  • 53
  • Seems not very standarized. Depends on desktop http://stackoverflow.com/questions/1049637/register-hotkeys-in-linux-using-library-for-c – Marco van de Voort Mar 04 '14 at 23:03
  • According to that link you placed XGrabKey is the standard for any XWindows window manager and should work no matter what. Maybe I'm reading the documentation wrong for XGrabKey. – jfreak53 Mar 05 '14 at 15:54
  • http://www.xfree.org/current/XGrabKey.3.html but I'm not sure how to use it in Lazarus. – jfreak53 Mar 05 '14 at 15:55

1 Answers1

1

Marco knows more about FPC than most (think he wrote it).

In any event you may find the code at the link below helpful and/or other portions of the code base:

http://code.google.com/p/ovoplayer/source/browse/trunk/src/platform/darwin/mmkeys.inc?spec=svn206&r=206

vitt
  • 11
  • 2