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

Hey, I'm trying to use Win32::API to call the RegisterHotKey function. However that links a hotkey with a window, and once i've linked it to my Win32::GUI::Window I have no idea how to the trap the resulting WM_HOTKEY message that should eb sent.

use Win32::GUI; use Win32::API; my $mw_win32 = new Win32::GUI::DialogBox( -width => 0, -height => 0, -name => 'MainWindow'); my $proto = 'BOOL RegisterHotKey(HWND hWnd, int id, UINT fsModifiers, +UINT vk)'; Win32::API->Import('user32', $proto) or die "import RegisterHotKey: $! + ($^W)"; # Call: my $ret = RegisterHotKey ($mw_win32->{-handle}, 1, 11||12 , 41); if (not $ret) { die "RegisterHotKey: $! ($^E)"; }

So any help would be appreciated. also if i've wandered down the completely wrong path please let me know! I'm using Win32::GUI + Tk to handle a systray icon and I'm hoping to add some hotkeys!...Thanks.


___________
Eric Hodges

Replies are listed 'Best First'.
Re: Windows Hotkey
by ldln (Pilgrim) on Jul 10, 2006 at 22:52 UTC
    doesn't answer your question, but have you considered using perltray?
Re: Windows Hotkey
by eric256 (Parson) on Jul 11, 2006 at 15:44 UTC

    Yet another try. Of coures i'm not even sure i'm calling RegisterHotKey correctly ;(

    #!/usr/bin/perl $| =1; use warnings; use strict; use Data::Dumper; use Win32::GUI; use Win32::API; my $proto = 'BOOL RegisterHotKey(HWND hWnd, int id, UINT fsModifiers, +UINT vk)'; Win32::API->Import('user32', $proto) or die "import RegisterHotKey: $! + ($^W)"; my $mw_win32 = new Win32::GUI::Window( -title => 'This is a test!', -width => 100, -height => 100, -name => 'MainWindow'); $mw_win32->Show(); # Call: my $ret = RegisterHotKey ($mw_win32->{-handle}, 10, 11 , 41); if (not $ret) { die "RegisterHotKey: $! ($^E)"; } print "Return: $ret\n"; $mw_win32->Hook( 273, sub {print "TEST"}); while (1) { Win32::GUI::DoEvents(); my $x = [$mw_win32->PeekMessage()]; print Dumper($x) if @$x > 1; }

    This still doesn't work, in fact the PeekMessage's doesn't appear to do anything at all! And the hook never fires either.


    ___________
    Eric Hodges
      Is this the same as a "Global Key"? Key that should work even if window is not in focus?

        Yes that is my goal. Create a hotkey that can do stuff even when the window is not in focus. /me begins searching for GlobalKey to see if that is different! ;)


        ___________
        Eric Hodges