FreePascal Global/System-wide hotkeys - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

FreePascal Global/System-wide hotkeys

AlGeorgeAlGeorge Posts: 1Member
Hi all. I have searched high and low for a resolution to what should be easy (but isnt) programming problem - how to define system-wide hotkeys using FP, most suitable for cross platform win/linux/osx
FP does not recommend using Windows API, rather its own internal messaging for cross platform.
If anyone could point me to url or make suggestions how to create a test case appreciate. FP has various keyboard routines such as Getkeystate, but nothing obviously fits.
Thanks kindly,
Alistair George.

Comments

  • _Atex__Atex_ Posts: 163Member
    : Hi all. I have searched high and low for a resolution to what should
    : be easy (but isnt) programming problem - how to define system-wide
    : hotkeys using FP, most suitable for cross platform win/linux/osx
    : FP does not recommend using Windows API, rather its own internal
    : messaging for cross platform.
    : If anyone could point me to url or make suggestions how to create a
    : test case appreciate. FP has various keyboard routines such as
    : Getkeystate, but nothing obviously fits.
    : Thanks kindly,
    : Alistair George.
    :

    Every OS treats the hotkeys differently, while under DOS one could just trap the keyboard interrupt, under Windows the specific API must be used. Linux is a different story, the keyboard there is actually a file: 'stdin', the extended keys are ESC sequences instead of ASCII. I don't now much about OSX, but it has something similar to Win API's called Cocoa. I guess it would be the most difficult to implement it for Linux. For a cross platform program one must follow different OS specific techniques to access hotkeys, a single function wont do. The only way I could think of is to use conditional compilation for the OS specific parts of your code. Something like:[code]
    // {$define win} {uncomment for windows }
    // {$define linux} {uncomment for linux }
    // {$define osx} {uncomment for}osx }

    {...}

    {$ifdef win} { windows specific function, hotkey must be registered first }
    function hotkeypressed:boolean; // <-- for Win this should be in the main loop
    var m:msg;
    begin
    if getmessage(@m,0,0,0) then begin
    hotkeypressed:=(m.message=wm_hotkey);
    translatemessage(@m);
    dispatchmessage(@m);
    end;
    end;
    {$endif}

    {...}

    {$ifdef linux}
    function hotkeypressed:boolean;
    begin
    { tough cookie, try to read "stdin" or use "ncurses" functions }
    end;
    {$endif}

    {...}

    {$ifdef osx}
    function hotkeypressed:boolean;
    begin
    // not sure if is there any FP wrapper for the Cocoa
    end;
    {$endif}[/code]
Sign In or Register to comment.