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

&H10, VK_CAPITAL As Byte = &H14, VK_NUMLOCK As Byte = &H90 Private events As New EventHandlerList Private hMouseHook, hKeyboardHook As Integer Private Shared MouseHookProcedure, KeyboardHookProcedure As HookProc Public Event MouseActivity As MouseEventHandler 'Public Custom Event MouseActivity As MouseEventHandler ' AddHandler(value As MouseEventHandler) ' events.AddHandler("MouseMove", value) ' End AddHandler ' RemoveHandler(value As MouseEventHandler) ' events.RemoveHandler("MouseMove", value) ' End RemoveHandler ' RaiseEvent(ByVal sender As Object, e As MouseEventArgs) ' Dim eh As MouseEventArgs = TryCast(events("MouseMove"), MouseEventArgs) ' If eh IsNot Nothing Then eh ' .Invoke(sender, e) ' End RaiseEvent 'End Event '键盘按下事件 Public Custom Event KeyDown As KeyEventHandler AddHandler(ByVal value As KeyEventHandler): events.AddHandler("KeyDown", value): End AddHandler RemoveHandler(ByVal value As KeyEventHandler): events.RemoveHandler("KeyDown", value): End RemoveHandler RaiseEvent(ByVal sender As Object, ByVal e As KeyEventArgs) Dim eh As KeyEventHandler = TryCast(events("KeyDown"), KeyEventHandler) If eh IsNot Nothing Then eh.Invoke(sender, e): End RaiseEvent: End Event '键盘输入事件 Public Custom Event KeyPress As KeyPressEventHandler AddHandler(ByVal value As KeyPressEventHandler): events.AddHandler("KeyPress", value): End AddHandler RemoveHandler(ByVal value As KeyPressEventHandler): events.RemoveHandler("KeyPress", value): End RemoveHandler RaiseEvent(ByVal sender As Object, ByVal e As KeyPressEventArgs) Dim eh As KeyPressEventHandler = TryCast(events("KeyPress"), KeyPressEventHandler) If eh IsNot Nothing Then eh.Invoke(sender, e): End RaiseEvent: End Event ' 键盘松开事件 Public Custom Event KeyUp As KeyEventHandler AddHandler(ByVal value As KeyEventHandler): events.AddHandler("KeyUp", value): End AddHandler RemoveHandler(ByVal value As KeyEventHandler): events.RemoveHandler("KeyUp", value): End RemoveHandler RaiseEvent(ByVal sender As Object, ByVal e As KeyEventArgs) Dim eh As KeyEventHandler = TryCast(events("KeyUp"), KeyEventHandler) If eh IsNot Nothing Then eh.Invoke(sender, e): End RaiseEvent: End Event Sub New() '留空即可 End Sub ' 创建一个全局鼠标键盘钩子,决定是否安装钩子 ''' <param name="InstallAll">是否立刻挂钩系统消息</param> Sub New(ByVal InstallAll As Boolean)

相关教程