Skip to content

Commit fdf0bc6

Browse files
Added XButton support in the Mouse Hook + Minor code fix.
Added XButton support in the Mouse Hook + Minor code fix.
1 parent 65c6ab0 commit fdf0bc6

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

InputHelper Library/InputHelper Library/InputHelper.vb

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'| |'
88
'| === COPYRIGHT LICENSE === |'
99
'| |'
10-
'| Copyright (c) 2016-2017, Vincent Bengtsson |'
10+
'| Copyright (c) 2016-2018, Vincent Bengtsson |'
1111
'| All rights reserved. |'
1212
'| |'
1313
'| Redistribution and use in source and binary forms, with or without |'
@@ -545,6 +545,8 @@ Public NotInheritable Class InputHelper
545545
Private LeftClickTimeStamp As Integer = 0
546546
Private MiddleClickTimeStamp As Integer = 0
547547
Private RightClickTimeStamp As Integer = 0
548+
Private X1ClickTimeStamp As Integer = 0
549+
Private X2ClickTimeStamp As Integer = 0
548550

549551
Private Function HookCallback(ByVal nCode As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
550552
Dim Block As Boolean = False
@@ -556,6 +558,8 @@ Public NotInheritable Class InputHelper
556558
wParam = NativeMethods.MouseMessage.WM_MBUTTONUP OrElse _
557559
wParam = NativeMethods.MouseMessage.WM_RBUTTONDOWN OrElse _
558560
wParam = NativeMethods.MouseMessage.WM_RBUTTONUP OrElse _
561+
wParam = NativeMethods.MouseMessage.WM_XBUTTONDOWN OrElse _
562+
wParam = NativeMethods.MouseMessage.WM_XBUTTONUP OrElse _
559563
wParam = NativeMethods.MouseMessage.WM_MOUSEWHEEL OrElse _
560564
wParam = NativeMethods.MouseMessage.WM_MOUSEHWHEEL OrElse _
561565
wParam = NativeMethods.MouseMessage.WM_MOUSEMOVE) Then
@@ -615,6 +619,27 @@ Public NotInheritable Class InputHelper
615619
Block = HookEventArgs.Block
616620

617621

622+
Case NativeMethods.MouseMessage.WM_XBUTTONDOWN
623+
Dim IsXButton2 As Boolean = (New NativeMethods.DWORD(MouseEventInfo.mouseData).High = 2)
624+
Dim DoubleClick As Boolean = (Environment.TickCount - If(IsXButton2, X2ClickTimeStamp, X1ClickTimeStamp)) <= NativeMethods.GetDoubleClickTime()
625+
626+
If IsXButton2 = True Then X2ClickTimeStamp = Environment.TickCount _
627+
Else X1ClickTimeStamp = Environment.TickCount
628+
629+
Dim HookEventArgs As New MouseHookEventArgs(If(IsXButton2, MouseButtons.XButton2, MouseButtons.XButton1), KeyState.Down, DoubleClick, _
630+
New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0)
631+
RaiseEvent MouseUp(Me, HookEventArgs)
632+
Block = HookEventArgs.Block
633+
634+
635+
Case NativeMethods.MouseMessage.WM_XBUTTONUP
636+
Dim IsXButton2 As Boolean = (New NativeMethods.DWORD(MouseEventInfo.mouseData).High = 2)
637+
Dim HookEventArgs As New MouseHookEventArgs(If(IsXButton2, MouseButtons.XButton2, MouseButtons.XButton1), KeyState.Up, False, _
638+
New Point(MouseEventInfo.pt.x, MouseEventInfo.pt.y), ScrollDirection.None, 0)
639+
RaiseEvent MouseUp(Me, HookEventArgs)
640+
Block = HookEventArgs.Block
641+
642+
618643
Case NativeMethods.MouseMessage.WM_MOUSEWHEEL
619644
Dim Delta As Integer = New NativeMethods.SignedDWORD(MouseEventInfo.mouseData).High
620645
Dim HookEventArgs As New MouseHookEventArgs(MouseButtons.None, KeyState.Up, False, _
@@ -741,7 +766,7 @@ Public NotInheritable Class InputHelper
741766
For Each Modifier As Keys In Modifiers
742767
InputList.Add(Keyboard.GetKeyboardInputStructure(Modifier, KeyDown, HardwareKey))
743768
Next
744-
InputList.Add(Keyboard.GetKeyboardInputStructure(Key, KeyDown, True))
769+
InputList.Add(Keyboard.GetKeyboardInputStructure(Key, KeyDown, HardwareKey))
745770

746771
NativeMethods.SendInput(CType(InputList.Count, UInteger), InputList.ToArray(), Marshal.SizeOf(GetType(NativeMethods.INPUT)))
747772
End Sub
@@ -1091,7 +1116,7 @@ Public NotInheritable Class InputHelper
10911116
''' <summary>
10921117
''' Checks whether a specific key is down in InputHelper's internal keyboard state (not related to the physical keyboard!).
10931118
''' </summary>
1094-
''' <param name="Key"></param>
1119+
''' <param name="Key">The key to check.</param>
10951120
''' <remarks></remarks>
10961121
Public Shared Function IsKeyDown(ByVal Key As Keys) As Boolean
10971122
If InputHelper.ExtractModifiers(Key).Length > 0 Then _
@@ -1131,7 +1156,8 @@ Public NotInheritable Class InputHelper
11311156

11321157
#Region "SendMouseClick()"
11331158
''' <summary>
1134-
''' Sends a Window Message-based mouse click to the window at the specified coordinates of the screen.
1159+
''' Sends a Window Message-based mouse click to the window located at the specified coordinates of the screen.
1160+
''' The coordinates are automatically translated to client coordinates and the click occurs in that specific point of the window.
11351161
''' </summary>
11361162
''' <param name="Button">The button to press.</param>
11371163
''' <param name="Location">The position where to send the click (in screen coordinates).</param>
@@ -1142,7 +1168,8 @@ Public NotInheritable Class InputHelper
11421168
End Sub
11431169

11441170
''' <summary>
1145-
''' Sends a Window Message-based mouse click to the window at the specified coordinates of the screen.
1171+
''' Sends a Window Message-based mouse click to the window located at the specified coordinates of the screen.
1172+
''' The coordinates are automatically translated to client coordinates and the click occurs in that specific point of the window.
11461173
''' </summary>
11471174
''' <param name="Button">The button to press.</param>
11481175
''' <param name="Location">The position where to send the click (in screen coordinates).</param>

InputHelper Library/InputHelper Library/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| |
88
| === COPYRIGHT LICENSE === |
99
| |
10-
| Copyright (c) 2016-2017, Vincent Bengtsson |
10+
| Copyright (c) 2016-2018, Vincent Bengtsson |
1111
| All rights reserved. |
1212
| |
1313
| Redistribution and use in source and binary forms, with or without |

InputHelper Library/InputHelper Library/My Project/AssemblyInfo.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Imports System.Runtime.InteropServices
1414
<Assembly: AssemblyDescription("A .NET friendly library for simulating mouse and keyboard input.")>
1515
<Assembly: AssemblyCompany("My DOOM site")>
1616
<Assembly: AssemblyProduct("InputHelper")>
17-
<Assembly: AssemblyCopyright("Copyright © Vincent Bengtsson 2016-2017")>
17+
<Assembly: AssemblyCopyright("Copyright © Vincent Bengtsson 2016-2018")>
1818
<Assembly: AssemblyTrademark("")>
1919

2020
<Assembly: ComVisible(False)>

0 commit comments

Comments
 (0)