Robert May wrote:
> > Has anyone gotten the system wide RegisterHotkey and UnrEgister hotkey
> > Win32 functions working with Win32::GUI and Win32::API?
> See here:
> http://www.mail-archive.com/[EMAIL PROTECTED]/msg05248.html
Hey great, thanks for the link and code, it works well. It even
demonstrates using a systray icon, which is incidentally something I'll
need to do as well in Win32::GUI but thought I'd figure that out on my
own based on the tutorial.
Now the only big question is what was the difference to my code?
In addition to more sophisticated event handling in the hook function
itself, and a separate set_hotkey function with reversed last two args,
the only major differences I can see is at a gllance, with a screen
reader, are as follows:
using the old style parameter names i and l in stead of INT and UINT
like I did. That is:
My code:
Win32::API->Import
(
user32 => # target window, some id, modifiers, virtual key code.
'BOOL RegisterHotKey(HWND w, int id, UINT mod, UINT vk)'
);
Your style:
Win32::API->Import('user32', 'RegisterHotKey', 'LiII', 'I');
You use an int in stead of bool in the return value, and also the two
last params are UINts in my case. I lifted the prototype straight from
the Windows SDk docs myself, though.
Another possibly crucial matter is the definition of the constants:
Mine:
use constant {MOD_CONTROL => 2, MOD_SHIFT => 4}; # HOtkey modifiers from
Your's:
sub MOD_CONTROL() {0x002} # Ctrl key
sub MOD_SHIFT() {0x004} # Shift key
The style you use is clearer, we're talking bit flags here.
Both 4 and 0x004 print 4, though,
Last but not least, you use a nice constant like:
VK_A
Where I use the ASCII value
ord 'q'
since I read in Petzold that the virtual key codes for letters are the
ASCII codes for those letters. Does the case matter normally or since
shift is down?
ord 'Q'; # is obviously quite different from the lowercase q.
Of course, it might be some different thing entirely that I've failed to
notice. The significant thing is that the register function does work,
letting me stay firmly in the Perl territory. I just find it a bit
unnerving that something suddenly works but I don't know why, <smile>.
Here are the significant snippets from my original:
# Constants.
use constant {MOD_CONTROL => 2, MOD_SHIFT => 4};
use constant qw|HOTKEY_ID 32|;
# Importing.
Win32::API->Import
(
user32 => # target window, some id, modifiers, virtual key code.
'BOOL RegisterHotKey(HWND w, int id, UINT mod, UINT vk)'
);
Win32::API->Import
(
user32 =>
'BOOL UnregisterHotKey(HWND w, int id)'
);
# Hooking and calling after having created win.
$win->Hook(WM_HOTKEY, \&key);
RegisterHotKey
(
$win->{'-handle'}, HOTKEY_ID,
MOD_SHIFT | MOD_CONTROL,
ord 'q'
) or die "HOtkey registration failed: $^E\n";
--
With kind regards Veli-Pekka Tätilä ([EMAIL PROTECTED])
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs