| 发表于:2007-10-26 13:29:411楼 得分:0 |
private sub form_load() hook end sub private sub form_unload(cancel as integer) unhook end sub ‘module1 option explicit private declare function callnexthookex lib "user32" _ (byval hhook as long, _ byval ncode as long, _ byval wparam as long, _ lparam as any) as long private declare function setwindowshookex lib "user32" _ alias "setwindowshookexa" _ (byval idhook as long, _ byval lpfn as long, _ byval hmod as long, _ byval dwthreadid as long) as long private declare function unhookwindowshookex lib "user32" _ (byval hhook as long) as long private declare sub copymemory lib "kernel32" _ alias "rtlmovememory" _ (destination as any, _ source as any, _ byval length as long) private type pkbdllhookstruct vkcode as long scancode as long flags as long time as long dwextrainfo as long end type private const wm_keydown = &h100 private const wm_syskeydown = &h104 private const wm_keyup = &h101 private const wm_syskeyup = &h105 private const hc_action = 0 private const wh_keyboard_ll = 13 private lnghook as long public function lowlevelkeyboardproc(byval ncode as long, _ byval wparam as long, _ byval lparam as long) as long dim blnhook as boolean dim p as pkbdllhookstruct if ncode = hc_action then select case wparam case wm_keydown, wm_syskeydown, wm_keyup, wm_syskeyup call copymemory(p, byval lparam, len(p)) if p.vkcode = vbkeyf8 then blnhook = true end if case else 'do nothing end select end if if blnhook then lowlevelkeyboardproc = 1 else call callnexthookex(wh_keyboard_ll, ncode, wparam, lparam) end if end function public sub hook() lnghook = setwindowshookex(wh_keyboard_ll, addressof lowlevelkeyboardproc, app.hinstance, 0) end sub public sub unhook() call unhookwindowshookex(lnghook) end sub | | |
|