Yes, thanks and this code works:
hook.c
#include <windows.h>
#include <WinAble.h>
#include "stdio.h"
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "hook.h"
HHOOK hook;
LRESULT CALLBACK HookCallback( int nCode, WPARAM wParam, LPARAM lParam
+ ) {
processKey();
return CallNextHookEx( hook, nCode, wParam, lParam );
}
void processKey() {
printf("processKey in C\n");
dSP;
PUSHMARK(SP);
int count= call_pv("Kbh::process_key", G_DISCARD|G_NOARGS);
if (count != 0)
croak("Big trouble\n");
}
void MsgLoop() {
MSG message;
while ( GetMessage( &message, NULL, 0, 0 ) ) {
TranslateMessage(&message);
DispatchMessage(&message);
}
}
void register_hook() {
HMODULE hMod = (HMODULE) GetModuleHandle(NULL);
hook = SetWindowsHookEx( WH_KEYBOARD_LL, HookCallback, hMod, 0 );
}
void unregister_hook() {
UnhookWindowsHookEx(hook);
}
Kbh.xs
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "hook.h"
MODULE = Kbh PACKAGE = Kbh
PROTOTYPES: DISABLE
void
MsgLoop()
void
register_hook()
void
unregister_hook()
The tricky part for me was to put the header in hook.c files in the right order.
François
|