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

Here's the work in progress, I haven't gotten around to printing the input to making sure it is getting what is being typed due to this error but, i'm sure i will mostlikely ask for advice and how one would go about it.
#!/usr/bin/perl -w use strict; use diagnostics; use Win32::API; my ($hook, $hooker, $idHOOK, $lpfn, $hmod, $dwThreadId); $idHOOK = 'WH_KEYBOARD_LL'; $lpfn = " " x 80; $hmod = 0; $dwThreadId = 0; $hook = new Win32::API('user32', 'SetWindowsHookEx', 'LLLL', 'L'); if(not defined $hook) { die "Can't import API SetWindowsHookEx: $!\n" } $hooker = $hook->Call($idHOOK, $lpfn, $hmod, $dwThreadId); #print $hooker;
Here's the error that is spit out.
D:\project>keyhook.pl Can't locate object method "API=HASH(0x15d4ebc)" via package "Win32" a +t D:\project\keyhook.pl line 16, <DATA> line 164 (#1) (F) You said to do (or require, or use) a file that couldn't be found. Perl looks for the file in all the locations mentioned in @ +INC, unless the file name included the full path to the file. Perhaps +you need to set the PERL5LIB or PERL5OPT environment variable to say w +here the extra library is, or maybe the script needs to add the library + name to @INC. Or maybe you just misspelled the name of the file. See perlfunc/require and lib. Uncaught exception from user code: Can't locate object method "API=HASH(0x15d4ebc)" via package " +Win32" at D:\project\keyhook.pl line 16, <DATA> line 164.
I'm not sure of what file th error is talking about i've used both user32 and the win32 module in programs before. Please shed some light on this for me.. thanks. Link to MSDN SetWindowsHookEx http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp

Replies are listed 'Best First'.
Re: Win32 Keyboard hook in perl
by bart (Canon) on Sep 10, 2004 at 00:02 UTC
    It's $hook->Call(...), not Call->$hook(...).
      thanks bart you fixed something i obviously overlooked. Now back to the other 82 problems heh :\
        Ok now please enlighten me on the proper way to create a pointer with the win32::api mod. I tried what the docs said exactly, $foo = " " x 80;
Re: Win32 Keyboard hook in perl
by simonm (Vicar) on Sep 10, 2004 at 00:02 UTC
    I don't know anything about Win32::API, but from a pure Perl point of view, I think you just need to replace "Call->$hook(" with "$hook->Call(".