in reply to Re: Creating keybinds GLOBALY!
in thread Creating keybinds GLOBALY!

That url gets me to microsoft.com...
Anyway, I want it in perl... Say we got this simple thing:
use Tk; my $main = new MainWindow(-title => "Global Testing"); $main->bind("<KeyPress>", sub {print "Hello there!"}); MainLoop;
Now, the binding doesnt work when window is out of focus... (as someone said is impossible to make working in tk in some other thread here at PerlMonks...)

Replies are listed 'Best First'.
Re^3: Creating keybinds GLOBALY!
by davis (Vicar) on Aug 05, 2005 at 08:58 UTC
    Anyway, I want it in perl...
    I really have to ask... why?
    You can make AutoHotkey run any abitrary program. I've used it to launch perl scripts, .bat scripts, etc. And yes, you're correct, you can't use Tk to bind a keypress when the window's out of focus. (At least, not that I know of)

    davis
    Kids, you tried your hardest, and you failed miserably. The lesson is: Never try.
      How about using Win32::API/Win32::GUI?
        Look, you're being dense. You've got your application that does god knows what. And lots of other applications are running at the same time. These other applications are possibly expecting to get input from the keyboard when they have "focus"; and you want to steal characters from them when your application isn't in focus.

        Your application shouldn't have to worry about intercepting ALL input EVER given to any other application, but that is exactly what will happen if you try to stuff this functionality into your application.

        Now, there are ways to fxck with the GUI such that some given input is redirected away from the application that has "focus" and instead goes about and does something else. Fine, great, dandy; there are uses for this sort of thing. And wow, autohotkey, as an example, does just that! Chances are very good that, if your program isn't specifically geared to do exactly and only that, ie try to imitate all the difficult bits that autohotkey and others have figured out, you'll do a completely sucky job at it.

        So, are you planning to write an imitation autohotkey all in perl? If so, I give you a pre-emptory -- for trying. You'd be screwing with user input with a language that will slow everything down a lot.

        If not, use autohotkey or someother similar product to do the input redirection, then concentrate on making your program do the thing it's supposed to do, and make sure it does it well.

        -Scott