资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

一个简单的键盘监视Hook,如何在生成.dll以后能够监测在windows系统下的键盘消息

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

Private   Declare   Function   SetWindowsHookEx   Lib   "user32"   Alias   "SetWindowsHookA"   (ByVal   idHook   As   Integer,   ByVal   lpfn   As   HookProc,   ByVal   hInstance   As   IntPtr,   ByVal   threadId   As   Integer)   As   Long  
   
          Private   Declare   Function   CallNextHookEx   Lib   "user32"   Alias   "CallNextHookA"   (ByVal   idHook   As   Integer,   ByVal   nCode   As   Integer,   ByVal   wParam   As   IntPtr,   ByVal   lParam   As   IntPtr)   As   Integer  
   
    Private   t   As   Double  
    Private   hHook   As   Double   =   0  
   
  Private   Delegate   Function   HookProc(ByVal   nCode   As   Integer,   ByVal   wParam   As   IntPtr,   ByVal   lParam   As   IntPtr)   As   Integer  
   
  Enum   ComHook  
                  WH_KEYBOARDKLL   =   2  
                  WH_MOUSE   =   7  
          End   Enum  
   
          Sub   SetHook()  
                  hHook   =   SetWindowsHookEx(2,   New   HookProc(AddressOf   MouseHookProc),   System.IntPtr.Zero,   0)  
          End   Sub  
          Public   Function   MouseHookProc(ByVal   nCode   As   Integer,   ByVal   wParam   As   IntPtr,   ByVal   lParam   As   IntPtr)   As   Integer  
                  If   nCode   <   0   Then  
                          Return   CallNextHookEx(hHook,   nCode,   wParam,   lParam)  
                  Else  
                          If   wParam.ToInt32   =   65   Then  
                                  StartThread()  
                          End   If  
                  End   If  
                  Dim   sPath   As   String  
                  Dim   FStream   As   StreamWriter  
                  sPath   =   "D:\BoardKeyFile.Txt"  
                  If   nCode   <   0   Then  
                          Return   CallNextHookEx(hHook,   nCode,   wParam,   lParam)  
                  Else  
   
                          If   File.Exists(sPath)   Then  
                                  FStream   =   New   StreamWriter(sPath,   True)  
                                  FStream.WriteLine(wParam)  
                                  FStream.Close()  
                          Else  
                                  File.Create(sPath)  
                                  FStream   =   New   StreamWriter(sPath,   True)  
                                  FStream.WriteLine(wParam)  
                                  FStream.Close()  
                          End   If  
                          Return   CallNextHookEx(hHook,   nCode,   wParam,   lParam)  
                  End   If  
          End   Function  
   
  高手帮我看看源码是否有问题,CallNextHookEx返回总是溢出

网友回答:

发表者:rzpc

VB.net不能使用HOOK  
  若要监视键盘,用Windows消息或HotKey的API


 

 
热门推荐笔记本: 海尔笔记本
相关文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved