When you have two mice hooked up to your computer, Windows XP will recognize all the mice as the same mouse. Any left click event from any of the mice will send a left click event to whatever window the cursor is on. There isn't a native way to distinguish between one mouse and another under windows XP, so it's difficult to set each mouse to do different things with its buttons.
Solution:
By using Michael Simon's package that allows control of a remote control device, we can obtain enough information from the HID messages that each mouse is sending in order to differentiate between one mouse and another, and create events specific for each mouse.
There are a few caveats to doing this though. First of all, all your mice have to be HID compliant. If you're using Windows XP, this is almost assuredly the case. Second of all, you need to download the package that Michael Simon provides that has his DLL which allows you to program remote control buttons. You can get it here: https://ahknet.autoh...Autohotkey.html Lastly, you have to disable all the buttons across the system. This is easy to do because Windows XP thinks that all the mice are the same mouse, so all you have to do is set up a basic mouse hotkey that disables the mouse buttons.
LButton::return
RButton::return
Etc., etc.
When you have these commands in a script, they will disable the buttons on all of your mice at the same time, because Windows XP "sees" those mice all as the same mouse. Then, we use Michael Simon's DLL to obtain the HID messages, which contain what buttons have been pressed and which mouse those buttons are attached to. Then it's a simple matter of sending an event in response to specific buttons being pressed by specific mice.
In my situation, I have a PS2 mouse for my left hand and a trackball for my right hand. I have to wear a carpal tunnel brace on my right-hand, which causes me to hit the buttons on the trackball accidentally. In this script, I have disabled the buttons on the second mouse, which in this case is the trackball, and allowed the first mouse, which is the PS2 mouse, to perform left click, right-click, and other mouse events. I've used a piece of tape over the PS2 mouse's "eye" to prevent it from moving the cursor while I'm holding it.
Here's the script I have come up with:
; ; ; MultiMice ; Author: [email protected] (See note below) ; Language: English ; Platform: WinXP ; Prerequisites: ; Michael Simon's "AutoHotkeyRemoteControlDLL" scripts and DLL's, which can be ; Obtained from https://ahknet.autohotkey.com/~Micha/HIDsupport/Autohotkey.html ; ; Note: Portions of this script are taken directly from Michael Simon's ; script "AutoHotkeyRemoteControlDLL.ahk", included in the package ; that can be obtained at the above URL. ; ; ; Load the RemoteControl dll and register the "Mouse" input device, which will register ; all connected mice at once, so we can begin obtaining WM_INPUT data and use it to determine ; which mouse's buttons are up and down, and what to do as a result ; HomePath=AutohotkeyRemoteControl.dll hModule := DllCall("LoadLibrary", "str", HomePath) ; Avoids the need for DllCall() in OnMessage(0x00FF, "InputMsg") OnExit cleanup DetectHiddenWindows, on Gui, Show, x0 y0 h0 w0, Autohotkey HID-Support HWND := WinExist("Autohotkey HID-Support") nRC := DllCall("AutohotkeyRemoteControl\RegisterDevice", INT, 2, INT, 1, INT, HWND, "Cdecl UInt") if (errorlevel <> 0) || (nRC == -1) { MsgBox RegisterDevice error. Errorcode: %errorlevel% goto cleanup } Winhide, Autohotkey HID-Support return ; ; The InputMsg function is called anytime a mouse sends an hid WM_INPUT message (sent during button or ; mouse movement), and is where we evaluate which mouse sent the message, which button is pressed ; or released when the message is sent, and what to do in response, if anything. ; InputMsg(wParam, lParam, msg, hwnd) { ; ; Each MX variable below is set to the device number as returned by the AutoHotkeyRemoteControlDLL ; script, while each MXLD (Mouse "X", Left Down, etc) variable is set to the cooresponding ; BtnFlag value that's returned when each button is pressed down or lifted up on. ; ; Be warned, the device number for these mice may change anytime you unplug/plugin an HID piece of ; hardware, or move your mice to different USB ports/etc, so you may end up editing this often if you ; screw around with your USB devices a lot. ; M1 = 11 M1LD = 1 M1LU = 2 M1RD = 4 M1RU = 8 M1MD = 16 M1MU = 32 ;M1X1D ;M1X1U ;M1X2D ;M1X2U ;M2 = 0 ;M2LD ;M2LU ;M2RD ;M2RU ;M2MD ;M2MU ;M2X1D ;M2X1U ;M2X2D ;M2X2U ;M3 = 0 ;M3LD ;M3LU ;M3RD ;M3RU ;M3MD ;M3MU ;M3X1D ;M3X1U ;M3X2D ;M3X2U nHandle := DllCall("AutohotkeyRemoteControl\GetWM_INPUTMOUSEData", UINT, wParam, UINT, lParam, "UINT *" , pusFlags, "UINT *", pusBtnFlg , "UINT *" , pusBtnData, "UINT *", pulRawBtn, "UINT *" , px, "UINT *", py, "UINT *", pextraInfo, "Cdecl UInt") if (errorlevel <> 0) || (nHandle == -1) { MsgBox GetWM_INPUTHIDData error. Errorcode: %errorlevel% goto cleanup } DeviceNumber := DllCall("AutohotkeyRemoteControl\GetNumberFromHandle", INT, nHandle, "Cdecl Int") DeviceNumber := DeviceNumber +1 ;Index 0 ; ; DeviceNumber is the mouse with the event, pusBtnFlg is the code for the button state, either pressed or released. ; if DeviceNumber = %M1% goto Mouse1Control ; else if DeviceNumber = %M2% ; goto Mouse2Control ; else if DeviceNumber = %M3% ; goto Mouse3Control else return ; ; Each MouseXControl section evaluates the contents of pusBtnFlg to determine which button went ; up or down, and based on that, you can have whatever event you wish occur. ; Mouse1Control: if pusBtnFlg = %M1LD% { Click down Right ; } else if pusBtnFlg = %M1LU% { Click up Right ; } else if pusBtnFlg = %M1RD% { Click down ; } else if pusBtnFlg = %M1RU% { Click up ; } else if pusBtnFlg = %M1MD% { Click down Middle ; } else if pusBtnFlg = %M1MU% { Click up Middle ; } ;else if pusBtnFlg = %M1X1D% ;{ ; Click down X1 ;; ;} ;else if pusBtnFlg = %M1X1U% ;{ ; Click up X1 ;; ;} ;else if pusBtnFlg = %M1X2D% ;{ ; Click down X2 ;; ;} ;else if pusBtnFlg = %M1X2U% ;{ ; Click up X2 ;; ;} else return ;Mouse2Control: ;if pusBtnFlg = %M2LD% ;{ ; Click down ;; ;} ;else if pusBtnFlg = %M2LU% ;{ ; Click up ;; ;} ;else if pusBtnFlg = %M2RD% ;{ ; Click down Right ;; ;} ;else if pusBtnFlg = %M2RU% ;{ ; Click up Right ;; ;} ;else if pusBtnFlg = %M2MD% ;{ ; Click down Middle ;; ;} ;else if pusBtnFlg = %M2MU% ;{ ; Click up Middle ;; ;} ;else if pusBtnFlg = %M2X1D% ;{ ; Click down X1 ;; ;} ;else if pusBtnFlg = %M2X1U% ;{ ; Click up X1 ;; ;} ;else if pusBtnFlg = %M2X2D% ;{ ; Click down X2 ;; ;} ;else if pusBtnFlg = %M2X2U% ;{ ; Click up X2 ;; ;} ;else return ;Mouse3Control: ;if pusBtnFlg = %M3LD% ;{ ; Click down ;; ;} ;else if pusBtnFlg = %M3LU% ;{ ; Click up ;; ;} ;else if pusBtnFlg = %M3RD% ;{ ; Click down Right ;; ;} ;else if pusBtnFlg = %M3RU% ;{ ; Click up Right ;; ;} ;else if pusBtnFlg = %M3MD% ;{ ; Click down Middle ;; ;} ;else if pusBtnFlg = %M3MU% ;{ ; Click up Middle ;; ;} ;else if pusBtnFlg = %M3X1D% ;{ ; Click down X1 ;; ;} ;else if pusBtnFlg = %M3X1U% ;{ ; Click up X1 ;; ;} ;else if pusBtnFlg = %M3X2D% ;{ ; Click down X2 ;; ;} ;else if pusBtnFlg = %M3X2U% ;{ ; Click up X2 ;; ;} ;else return } ; ; Disable all buttons on all connected mice. If we don't do this, then the left button on all the mice ; will always send a left click, etc etc. Once all buttons are disabled, we use this script to simulate ; the normal operation of the mice, only we do so for each particular mouse we wish to enable it with, ; thereby giving us custom control of each mouse individually. ; ; Also, set up a keyboard shortcut that will kill the program gracefully with a {RWin} & q keyboard ; combination (Right Windows Key and "q" key at the same time). ; >#q:: MsgBox Application Quit! goto cleanup return LButton::return RButton::return MButton::return XButton1::return xButton2::return cleanup: DllCall("FreeLibrary", "UInt", hModule) ; It is best to unload the DLL after using it (or before the script exits). ExitApp
I did some searching on the forum looking for information on how to use multiple mice with the computer, and while I found a lot of people saying that it was possible, especially with Michael Simon's DLL, I didn't find anyone who had successfully created a script to do so. So I wrote this one, and thought I would post it here in case it helps anyone else in the future.
This is a pretty simple script, and I've only done a little bit of testing with it. But this should serve the purpose most people are looking for that want to use two or more mice at the same time. Whether you're actively going to use both mice to control the cursor, or if you simply want to use the second mouse to do specific hotkeys or shortcut functions, this script should do the trick.
If anybody spots something in it that could be improved or done in a better way, please let me know. I really don't do much programming anymore, and I've never done programming for Windows. This is probably the most complicated script I've done in years, and most of it I just stole from Michael Simon. >;)