Yo....So i'm still trying to get this hot key thing to work and i've gotten a little farther...maybe. I found the right API calls to hook a windows messages. I'm getting all sorts of messages about a Win32::GUI window I created, keystrokes etc. The problem is the hotkey message still isn't coming through. So i think there is a problem specificaly with either the hWnd returnd by Win32::GUI or the constants I've used, or my understanding of the problem at all. So if any Win32 gurus could lend me an eyeball and maybe a few brain cells i'd appreciate it.

use warnings; use strict; use Tk; use Win32::API; use Win32::GUI; use Win32::API::Callback; use constant WH_MSGFILTER => -1; use constant WH_JOURNALRECORD => 0; use constant WH_JOURNALPLAYBACK => 1; use constant WH_KEYBOARD => 2; use constant WH_GETMESSAGE => 3; use constant WH_CALLWNDPROC => 4; use constant WH_CBT => 5; use constant WH_SYSMSGFILTER => 6; use constant WH_MOUSE => 7; use constant WH_HARDWARE => 8; use constant WH_DEBUG => 9; use constant WH_SHELL => 10; use constant WH_FOREGROUNDIDLE => 11; use constant WH_CALLWNDPROCRET => 12; use constant WH_KEYBOARD_LL => 13; use constant WH_MOUSE_LL => 14; use constant MOD_CONTROL => 2; use constant KEY_A => 65; my $mw_win32 = new Win32::GUI::Window( -title => 'This is a test!', -width => 100, -height => 100, -name => 'MainWindow'); my $GetCurrentThreadId = new Win32::API('kernel32', 'GetCurrentThrea +dId', '', 'N'); my $SetWindowsHookEx = new Win32::API('user32' , 'SetWindowsHookE +x' , 'NKNN', 'N'); my $CallNextHookEx = new Win32::API('user32' , 'CallNextHookEx' + , 'PNNN', 'N'); Win32::API->Import('user32', 'BOOL RegisterHotKey(HWND hWnd, int id, U +INT fsModifiers, UINT vk)') or die "import RegisterHotKey: $! ($^W)"; sub KeyboardHook($$$) { my ($nCode, $wParam, $lParam) = @_; print "nCode=$nCode, wParam=$wParam, lParam=$lParam\n"; $CallNextHookEx->Call(0, $nCode, $wParam, $lParam); } # LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam, LPARAM lParam) +; sub WindowProc($$$) { my ($nCode, $wParam, $lParam) = @_; print "nCode=$nCode, wParam=$wParam, lParam=$lParam\n"; print "***************" if $wParam == 273; $CallNextHookEx->Call(0, $nCode, $wParam, $lParam); } my $WinProc = new Win32::API::Callback(\&WindowProc , ' +NNN', 'N'); my $KeyboardHookCallback = new Win32::API::Callback(\&KeyboardHook, ' +NNN', 'N'); my $ThreadId = $GetCurrentThreadId->Call() or die; my $Hook = $SetWindowsHookEx->Call(WH_KEYBOARD , $KeyboardHookC +allback, 0 , $ThreadId) or die $^E; my $ProcHook = $SetWindowsHookEx->Call(WH_GETMESSAGE , $WinProc, 0 , $ +ThreadId) or die $^E; #WH_CALLWNDPROC print $mw_win32->{-handle}; my $hotkey = RegisterHotKey ($mw_win32->{-handle}, 99, MOD_CONTROL, +KEY_A) or die $^E; $mw_win32->Show(); Win32::GUI::Dialog();

___________
Eric Hodges

In reply to Continueing the Quest to get RegisterHotKey to work! by eric256

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.