| 发表于:2007-09-07 20:28:48 楼主 |
我亲爱的键盘啊!这么多年风风雨雨都过来了,为什么偏偏在这个时候不好用了呢?你哪个回车键,为什么一按下去就不弹起来了呢?我曾经试着用拳头砸过你,没有用;我又用锤头砸过你,结果回车键更弹不起来了!有心将你弃之东隅,但转念一想,我抚摸了这么长时间、对我这么有感情的东西,怎么能将它放弃呢?硬的不行,只好,来点软的吧!于是乎,我七拼八凑,写了点代码,将你搞定。 模块中: private hhook 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 declare function callnexthookex lib "user32 " _ (byval hhook as long, _ byval ncode as long, _ byval wparam as long, _ lparam as any) as long private declare sub copymemory lib "kernel32.dll " alias "rtlmovememory " (byref destination as any, byref source as any, byval length as long) '很多没用的,也加上了 private const wh_callwndproc = 4 private const wh_callwndprocret = 12 private const wh_cbt = 5 private const wh_debug = 9 private const wh_foregroundidle = 11 private const wh_getmessage = 3 private const wh_hardware = 8 private const wh_journalplayback = 1 private const wh_journalrecord = 0 private const wh_keyboard = 2 private const wh_mouse = 7 private const wh_msgfilter = (-1) private const wh_shell = 10 private const wh_sysmsgfilter = 6 private const wh_keyboard_ll = 13 private const wh_mouse_ll = 14 private const hc_action as integer = 0 private const wm_keydown = &h100 private const wm_keyup = &h101 private const wm_syskeydown as integer = &h104 private const wm_syskeyup as integer = &h105 private type eventmsg wmsg as long lparaml as long lparamh as long msgtime as long hwndmsg as long end type private emsg as eventmsg dim lasttimer as double public sub unhookkbd() if hhook <> 0 then unhookwindowshookex hhook hhook = 0 end if end sub public function enablekbdhook() if hhook <> 0 then exit function end if hhook = setwindowshookex(wh_keyboard_ll, addressof _ mykbhfunc, app.hinstance, byval 0&) end function private function mykbhfunc(byval icode as long, _ byval wparam as long, byval lparam as long) as long if icode <> hc_action then exit function if wparam = wm_keydown or wparam = wm_keyup or wparam = wm_syskeyup or wparam = wm_syskeydown then copymemory emsg, byval lparam, len(emsg) if emsg.wmsg = 13 then '侦测 有没有按到enter键 if abs(lasttimer - timer) <= 0.05 then mykbhfunc = 1 '在这个hook便吃掉这个讯息 lasttimer = timer exit function end if end if call callnexthookex(hhook, icode, wparam, lparam) '传给下一个hook end function 窗口中: private sub form_load() enablekbdhook end sub private sub form_unload(cancel as integer) unhookkbd end sub 只要我在使用键盘前,打开这个小程序,就不会出现因长时间连续按回车键而无数次打开同一个程序而死机了! |
|
|
|
|