[quote=185995:@jim mckay]Ok, since I suggested it…
You could either use a module or a class (slightly more complicated)
in a module…
add a property
Hook as integer
add a structure
KBDLLHOOKSTRUCT
{
keyCode as uint32
scanCode as uint32
flags as uint32
time as uint32
extraInfo as ptr
}
and 4 methods
[code]Sub Start()
#if TargetWin32
const WH_KEYBOARD_LL=13
soft Declare function SetWindowsHookExA lib "User32" (idHook as integer, lpfn as ptr, hMod as integer,dwThreadId as integer) as integer
if hook<>0 then return
hook= SetWindowsHookExA(WH_KEYBOARD_LL,AddressOf KeyCallback,0,0)
#endif
End Sub
Function HandleKeyPress(keyCode as integer,down as Boolean) As Boolean
System.DebugLog(str(keyCode))
Return false
End Function
Function KeyCallBack(code as int32, wParam as uint32, byref lParam as KBDLLHOOKSTRUCT) As int32
#if TargetWin32
const WM_KEYDOWN =&h100
soft Declare function CallNextHookEx lib “User32” (hhk as integer,nCode as int32,wParam as uint32,byref lParam as KBDLLHOOKSTRUCT) as int32
if code<0 or (not HandleKeyPress(lParam.keyCode,wParam=WM_KEYDOWN)) then Return CallNextHookEx(0,code,wParam,lParam)
Return -1
#endif
End Function
Sub Stop()
#if TargetWin32
soft Declare function UnhookWindowsHookEx lib "User32" (idHook as integer) as integer
call UnhookWindowsHookEx(hook)
hook=0
#endif
End Sub
[/code]
To start monitoring key events call
WinKeyStrokeMonitor.Start
To stop call
WinKeyStrokeMonitor.Stop
now, in the handleKeyPress method, you can return true to prevent the event from moving up the call chain by returning true.
eg.
if keyboard.AsyncControlKey and keyCode=&h12 then
//do stuff
return true //prevents "a" from being typed.. should also supersede any menus
end if
[/quote]
Thankyou very much for the suggestion. I already came up with my own code that works cross platform to handle this.
Thanks