Foggy Bottoms has asked for the wisdom of the Perl Monks concerning the following question:

Dearest monks,

I've been working on getting a hotkey to work with Perl regardless of the fact that the perl window is active. I figured I'd probably need to write some sort of separate thread and have it listen to the keyboard permanently. If a key were pressed then it could send the perl app an order to focus (for example).
I need to do some low-level programming with the keyboard but unfortunately I have very little experience. Could someone please help me out ?

Heureux qui, comme Ulysse, a fait un beau voyage
Ou comme celui-là qui conquit la Toison,
Et puis est retourné plein d'usage et raison,
Vivre entre ses parents le reste de son âge!

J. du Bellay, poëte angevin

Replies are listed 'Best First'.
Re: hotkey...again
by BrowserUk (Patriarch) on Jun 19, 2003 at 10:52 UTC

    If your aiming for a cross-platform solution, I doubt that there is an easy answer to this.

    If your aiming at the Windows platform, then you may be able to do something with the latest version of dada's Win32API and use it to call user32.dll:RegisterHotkey and/or possibly user32.dll:RegisterShellHookWindow. You would need to get the system to call your code when your chosen hotkey is pressed. The latest version (0.41) of Win32::API purports to allow you to call win32 native APIs that require a callback address, though I haven't used that functionality yet.

    You would probably need to create a gui window to act as the windowproc for callback. You might look at Win32::GUI to do that. There are also many useful functions in the Win32::GUITest module that would be useful for giving your window the focus etc. if and when you can get the system to call you.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Re: hotkey...again
by gellyfish (Monsignor) on Jun 19, 2003 at 10:17 UTC

    What operating system are we talking about here ?

    /J\