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

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

Replies are listed 'Best First'.
Re^6: Creating keybinds GLOBALY!
by BrowserUk (Patriarch) on Aug 05, 2005 at 18:57 UTC

    Actually, it's totally possible to do this under windows. The relevant API is SetSystemWindowHookEx.

    Basically, all keyboard (and mouse) input goes through a system queue first before being distributed to individual process and thread queues. The above API allows you to add a hook to this queue and have your application be called back everytime any input is received by the system queue.

    However, from experience it is extremely difficult to get right. It also involves providing a callback address (which from Perl would need to be a perl funcition), and I've never managed to get that to work using Win32::API, hence my not recommending it.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
      I'd figured it was possible, even figured he had the right Win32 module; I was just trying to disuade the OP from attempting to just tack this functionality onto the side of his existing application. It's not likely to be the right thing to do... If it is, I hope he bulldozes through all of those warning him not to do it & eventually posts a CUFP or Snippet on how to do it correctly.

      -Scott

Re^6: Creating keybinds GLOBALY!
by Ace128 (Hermit) on Aug 19, 2005 at 18:25 UTC
    Well, the thing is that this is supposed to be done in a controlled way. That means that the user is supposed to define the GLOBAL key(combination), or its something like CTRL+Shift+U (and thus not interfearing with normal use). Reason I want this is so I DO NOT have to have the application in focus, just running, and get it to react when _I_ want to. Say, pressing that CTRL+Shift+U and my application in Perl gives me some input window or something... and the Perl application have now focus...