Two mice = two cursors in AutoIt

5 posts in this topic

; AutoIt DualMouse demo, by lod3n

; you will need to have RawMouseDemo.exe from http://jstookey.com/arcade/rawmouse/ (C# demo)
; (direct download: http://jstookey.com/arcade/rawmouse/rawinputsharp.zip )
; located in the script dir for this to work. All I am really doing is reading the values 
; from that window.

; There is source code, and a DLL included in that download. If someone felt up to it, it 
; would be interesting to see something a little more AutoIt compatible created, like 
; a Plugin or an object or something. Perhaps it can all be done with window messages...

; That, combined with the prospeed dll, you could make some cool games, who knows. 
; There are also some interesting interfaces out there that use multi-touch, for instance:
; letting you resize an image by grabbing two edges of it, 3d interaction, two users 
; on the same screen doing something to the same interface. I was thinking that it might 
; be fun to try and develop some kind of 4 dimensional text input interface. Ideally, 
; this could replace a traditional keyboard, though I am not real sure as to how...

; At the moment, clicking is not possible, as I can't read the click state checkboxes 
; on RawMouseDemo, so this isn't really good for much, it's just food for thought.

; If you use this for anything fun, or find a better way to do DualMouse in AutoIt, please
; let me know.

#include <Misc.au3>
#include <GUIConstants.au3>
Global $WS_EX_NOACTIVATE = 0x8000000
Global $pid = 0
if not HotKeySet ("{esc}", "goQuit") Then
    msgbox(16, "Error","Could not set Esc as the hotkey to quit, which would prevent you from being able to shut down the demo. Quitting.")
msgbox(0,"AutoIt DualMouse demo, by lod3n","Demo starting, press ESC to quit."&@crlf&@crlf&"Also, make sure you have both mice plugged in or this won't be very interesting.")

global $pid = run(@scriptdir & "\RawMouseDemo.exe",@scriptdir,@SW_SHOW)
$hwnd = WinGetHandle("RawMouseDemo")

; positions
$pMouse1x = ControlGetHandle($hwnd,"","WindowsForms10.EDIT.app36")
$pMouse1y = ControlGetHandle($hwnd,"","WindowsForms10.EDIT.app35")
$pMouse1mid = ControlGetHandle($hwnd,"","WindowsForms10.EDIT.app34")
$pMouse2x = ControlGetHandle($hwnd,"","WindowsForms10.EDIT.app33")
$pMouse2y = ControlGetHandle($hwnd,"","WindowsForms10.EDIT.app32")
$pMouse2mid = ControlGetHandle($hwnd,"","WindowsForms10.EDIT.app31")

; button states - useless, as ControlCommand cannot read the IsChecked status!
$bMouse1left = ControlGetHandle($hwnd,"","WindowsForms10.BUTTON.app36")
$bMouse1right = ControlGetHandle($hwnd,"","WindowsForms10.BUTTON.app35")
$bMouse1mid = ControlGetHandle($hwnd,"","WindowsForms10.BUTTON.app34")
$bMouse2left = ControlGetHandle($hwnd,"","WindowsForms10.BUTTON.app33")
$bMouse2right = ControlGetHandle($hwnd,"","WindowsForms10.BUTTON.app32")
$bMouse2mid = ControlGetHandle($hwnd,"","WindowsForms10.BUTTON.app31")

; set up child gui
$client = WinGetClientSize($hwnd)
$gui = GUICreate("MouseHooky", $client[0], $client[1], 0, 0, $WS_POPUP, $WS_EX_NOACTIVATE + $WS_EX_TOOLWINDOW)
$xoffset = $client[0]/2
$yoffset = $client[1]/2

; mouse 1 "cursor"
$m1 = GUICtrlCreateIcon ("shell32.dll", 23, $xoffset-100,$yoffset)

; mouse 2 "cursor"
$m2 = GUICtrlCreateIcon ("shell32.dll", 15, $xoffset+100,$yoffset)

; attach child gui RawMouseDemo gui, required because RawMouseDemo must be
; the active window to read the positions from the mice
DllCall("user32.dll", "int", "SetParent", "hwnd", $gui, "hwnd", $hwnd)


_CurVisInv(0) ;hide the real mouse cursor, not required, but less confusing
while 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE then Exit
    ; trap the real mouse in a 1x1 cage, to prevent accidentally clicking out of the 
    ; demo window, which will disable the effect, as noted abouve
    $coords = WinGetPos($GUI)
    _MouseTrap ($coords[2]-4, $coords[3]-4, $coords[2]-4, $coords[3]-4)
    ; read the 2 mice positions, and move the "cursors" to match
    GUICtrlSetPos ( $m1, ControlGetText($hwnd,"",$pMouse1x)+$xoffset-100,ControlGetText($hwnd,"",$pMouse1y)+$yoffset)
    GUICtrlSetPos ( $m2, ControlGetText($hwnd,"",$pMouse2x)+$xoffset+100,ControlGetText($hwnd,"",$pMouse2y)+$yoffset)
    if not ProcessExists($pid) then goQuit()


func goQuit()
    _MouseTrap ()

Func _CurVisInv($bV)
  Local $cursorinternalc
     Case $bV = 1
           $cursorinternalc = DllCall("User32.dll", "long", "ShowCursor", "long", $bV)
        Until $cursorinternalc[0] > 0
     Case $bV = 0
           $cursorinternalc = DllCall("User32.dll", "long", "ShowCursor", "long", $bV)
        Until $cursorinternalc[0] < 0
     Case Else
        Return 0

 ;MsgBox(0, '', $cursorinternalc[0])
  Return 1
EndFunc  ;==>_CurVisInv

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post

Link to post
Share on other sites

I cant find anywhere the exe on your site.


Share this post

Link to post
Share on other sites

It's inside this zip:


Under \RawMouseDemo\Bin\Release\RawMouseDemo.exe

You also need the RawInputSharp.dll, i'm just now realizing.

In case that isn't working, I will upload the files as attachments to this post, but you really ought to use the one from the zip.



[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post

Link to post
Share on other sites

First off, does this work on Windows 10 or just Linux/BSD Unix?

2) are there detailed step by step instructions available?

3) I currently have 2 track ball mice that I bought on eBay from Japan, one Left handed & the other Right handed, currently the both control the same cursor & the buttons are all set the dame way. I like this becsuse as I'm getting older, I start to forget the little things, like which mouse button does what.

4) All I really want is to assign different cursors to each of the trackballs. If I can set their colours and visual effects differently for each mouse, I would buy this app or at least throw some money towards the author's PayPal account.


Evil Dave of Canada

Share this post

Link to post
Share on other sites


Welcome to the AutoIt forums.

But did you notice that the post above yours dates from some 9.5 years ago and that the OP has not been on the forum for over 5 years? So I think it unlikely that you will get a reply.

In future, please do not necro-post in threads from so long ago - the language has changed so much that it is possible that the functionality has already been incorporated (although not in this case) and the previously posted code will almost certainly not run in the current version of AutoIt without modification.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now