Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
FreePascal Global/System-wide hotkeys Posted by AlGeorge on 14 Mar 2011 at 12:05 PM
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.
Report
Re: FreePascal Global/System-wide hotkeys Posted by _Atex_ on 15 Mar 2011 at 10:07 PM
: 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}




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.