您的位置:程序门 -> vb ->



怎么屏蔽键盘上的 f8键


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


怎么屏蔽键盘上的 f8键
发表于:2007-10-26 12:55:35 楼主
想请教大家一下,怎么在程序中屏蔽掉   f8键。
也就是说程序运行后,f8键就失去功能。
发表于: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
       
发表于:2007-10-26 13:56:212楼 得分:0
谢谢。
再请教一下,没分了
我还想屏蔽鼠标右键,就是程序运行后,鼠标右键就无效。
真是不好意思。
发表于:2007-10-26 14:25:523楼 得分:0
?
发表于:2007-10-26 14:25:414楼 得分:0
?


快速检索

最新资讯
热门点击