Sign in to follow this  
Followers 0
lod3n

Two mice = two cursors in AutoIt

3 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.")
    Exit
EndIf
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)
WinWait("RawMouseDemo")
$hwnd = WinGetHandle("RawMouseDemo")
WinSetState($hwnd,"",@SW_MAXIMIZE)

; 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)
GUISetBkColor(0xFF0000,$gui)
$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)

GUISetState(@SW_SHOW)
WinActivate($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()
WEnd

goQuit()

func goQuit()
    ProcessClose($pid)
    _CurVisInv(1)
    _MouseTrap ()
    Exit
EndFunc

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

 ;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.


-jaenster

Share this post


Link to post
Share on other sites

It's inside this zip:

http://jstookey.com/arcade/rawmouse/rawinputsharp.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.

RawMouseDemo.exe

RawInputSharp.dll


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

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
Sign in to follow this  
Followers 0