: 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:
// {$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}