VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > VB.net教程 >
  • VB.net / IO / 获取鼠标键盘事件的钩子函数

VB.net / IO / 获取鼠标键盘事件的钩子函数

VB.net 中获取鼠标键盘的钩子函数。可以将代码粘贴至一个新建模块,然后在主程序中声明一个Hook,调用Hook的事件就可以得到鼠标键盘的返回值了。(原谅我把VB.net写出了Python风格…)
 

Imports System.Reflection
 Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports System.Windows.Forms
Public Class SystemHook

 Private Structure MouseHookStruct
    Dim X,Y As Single, Hwnd, WHitTestCode, DwExtraInfo As Integer: End Structure
 Private Structure MouseLLHookStruct
    Dim X,Y As Single, MouseData, Flags, Time, DwExtraInfo As Integer: End Structure
 Private Structure KeyboardHookStruct
    Dim vkCode, ScanCode, Flags, Time, DwExtraInfo As Integer:    End Structure
 Public myeor As String


Private Declare Function SetWindowsHookExA Lib "user32" (ByVal idHook As Integer, ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal dwThreadId As Integer) As Integer
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Int32, ByVal lpfn As HookProc, ByVal hMod As IntPtr, ByVal dwThreadId As Int32) As Int32
'SetWindowsHookEx(安装的钩子的类型,消息的处理函数,应用程序事例句柄,线程ID) 
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal idHook As Int32) As Int32
Private Declare Function CallNextHookEx Lib "user32" (ByVal idHook As Int32, ByVal nCode As Int32, ByVal wParam As Int32, ByVal lParam As IntPtr) As Int32
Private Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Int32, ByVal uScancode As Int32, ByVal lpdKeyState As Byte(), ByVal lpwTransKey As Byte(), ByVal fuState As Int32) As Int32
Private Declare Function GetKeyboardState Lib "user32" (ByVal pbKeyState As Byte()) As Int32
Private Declare Function GetKeyState Lib "user32" (ByVal vKey As Int32) As Short
Private Delegate Function HookProc(ByVal nCode As Int32, ByVal wParam As Int32, ByVal lParam As IntPtr) As Int32


Private Const WH_MOUSE_LL = 14, WH_KEYBOARD_LL = 13, WH_MOUSE = 7, WH_KEYBOARD = 2, WM_MOUSEMOVE = &H200, WM_LBUTTONDOWN = &H201, WM_RBUTTONDOWN = &H204, WM_MBUTTONDOWN = &H207, WM_LBUTTONUP = &H202, WM_RBUTTONUP = &H205, WM_MBUTTONUP = &H208, WM_LBUTTONDBLCLK = &H203, WM_RBUTTONDBLCLK = &H206, WM_MBUTTONDBLCLK = &H209, WM_MOUSEWHEEL = &H20A, WM_KEYDOWN = &H100, WM_KEYUP = &H101, WM_SYSKEYDOWN = &H104, WM_SYSKEYUP = &H105, VK_SHIFT As Byte =
      



  

相关教程