in reply to How can I read keyboard "in the background"

It seems to me you are looking for an "event -driven" script. Tk does this, it will enter an "event loop" and watch for various types of events. A real simple example:
#!/usr/bin/perl use Tk; my $mw = new Tk::MainWindow; my $btn = $mw->Button(-text => 'Hit Return')->pack(); # # Note that we *usually* bind to the main window, # not the button - it's a focus thing. # $mw->bind('<Return>', \&_on_rtn); MainLoop; exit(0); sub _on_rtn { $mw->messageBox(-message=>'Thanx for using the keyboard!'); }

Replies are listed 'Best First'.
Re: Re: How can I read keyboard "in the background"
by Foggy Bottoms (Monk) on Jun 10, 2003 at 15:34 UTC
    Well it's not quite what I'm looking for : I'd like for the window to react (just like in your script) whether it's active ot not (focused or blurred) which isn't the case in your script.
    If for example you're working in MS Word and you press the return key, then MS Word solely deals with it whereas I'd like for the perl script in the background to react as well. Thanks for your help !
      I think you'll want to write a Word macro or some VB or VBA that will call your Perl script, passing it the current application and filename.
      I think you might be looking for a way to bind keys at the x server level. Something like hit F11 and "someapp" jumps into focus. How about xbindkeys?
        Well actually I'm running under Win NT so I can't really use X Window. Basically I'm looking for a hotkey method, if you've any idea.
        Thanks for ur help.
      I beleive that what you want would require rewriting the Windows keyboard drivers or at least piggybacking the interrupts.