Hook mouse click in Inventor.

Hook mouse click in Inventor.

yuzeaa
Advocate Advocate
229 Views
0 Replies
Message 1 of 1

Hook mouse click in Inventor.

yuzeaa
Advocate
Advocate

Firstly, I don't want to use mouse events. I want to create a global hook in Inventor so that I can customize the desired functionality as a shortcut. Whenever I press the mouse middle button at any time, its behavior will be determined by the current document environment and some other conditions.Is that possible?

Following codes crashed in Inventor but worked in windows forms.

Imports System.Runtime.InteropServices
Public Class ThisRule
	
    Private Delegate Function MouseHookDelegate(nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr

    <DllImport("user32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
    Private Overloads Shared Function SetWindowsHookEx(idHook As Integer, HookProc As MouseHookDelegate, hInstance As IntPtr, wParam As Integer) As IntPtr
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
    Private Overloads Shared Function CallNextHookEx(idHook As IntPtr, nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
    End Function

    <DllImport("user32.dll", CharSet:=CharSet.Auto, CallingConvention:=CallingConvention.StdCall)>
    Private Overloads Shared Function UnhookWindowsHookEx(idHook As IntPtr) As Boolean
    End Function

    Private Const WH_MOUSE_LL As Integer = 14
    Private Const WM_MOUSEMOVE As Integer = &H200
    Private Const WM_LBUTTONDOWN As Integer = &H201
    Private Const WM_LBUTTONUP As Integer = &H202
    Private Const WM_RBUTTONDOWN As Integer = &H204
    Private Const WM_RBUTTONUP As Integer = &H205
    Private Const WM_MBUTTONDOWN As Integer = &H207
    Private Const WM_MBUTTONUP As Integer = &H208

    Private mouseHook As IntPtr
    Private mouseDelegate As MouseHookDelegate

    Private Function MouseHookCallback(nCode As Integer, wParam As IntPtr, lParam As IntPtr) As IntPtr
        If nCode >= 0 AndAlso wParam = New IntPtr(WM_MBUTTONDOWN) Then
            MessageBox.Show("Middle mouse button pressed!")
        End If

        Return CallNextHookEx(mouseHook, nCode, wParam, lParam)
    End Function

    Private Sub StartHook()
        mouseDelegate = New MouseHookDelegate(AddressOf MouseHookCallback)
        mouseHook = SetWindowsHookEx(WH_MOUSE_LL, mouseDelegate, IntPtr.Zero, 0)
    End Sub

    Private Sub StopHook()
        UnhookWindowsHookEx(mouseHook)
    End Sub
	
    Private Sub main
        StartHook()
    End Sub
End Class

 

0 Likes
230 Views
0 Replies
Replies (0)