Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Second cursor controlled via second mouse


  • Please log in to reply
4 replies to this topic
GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009
I just made a script that gives you two cursors with two mice!
You need AHKHID in your lib folder for it to work though...
To use you just move your first mouse first, then your second mouse.
Please criticize my code.

NOTE: It does not support middle mouse button

CoordMode, Mouse, Screen
BlockInput, MouseMove
Global mouse1
Global mouse2
Global Stage = 1

Gui, Color, 000000
Gui, -Caption +AlwaysOnTop +ToolWindow +LastFound
Gui, show, w30 h30 x0 y0, luuu
WinSet, Region, 0--1 0-16 1-16 5-12 7-12 11-12 11-10, luuu
GuiHandle := WinExist()
Gui, Show

SetFormat, FloatFast, 3.0

AHKHID_UseConstants()
OnMessage(0x00FF, "InputMsg")
AHKHID_Register(1, 2, GuiHandle, RIDEV_INPUTSINK)
Return

LButton::
RButton::
Return

Escape::
GuiClose:
AHKHID_Register(1, 2, 0, RIDEV_REMOVE)
ExitApp

InputMsg(wParam, lParam) {
	Local x, y
	m := AHKHID_GetInputInfo(lParam, 8)
	If (Stage) {
		If (Stage = 1) {
			Mouse1 := m
			Stage = 2
		} Else If (Stage = 2 && m != Mouse1) {
			Mouse2 := m
			Stage = 0
		}
		Return
	}
	
	x := AHKHID_GetInputInfo(lParam, II_MSE_LASTX)
	y := AHKHID_GetInputInfo(lParam, II_MSE_LASTY)
	b := AHKHID_GetInputInfo(lParam, II_MSE_BUTTONFLAGS)
	
	If !(x || y || b)
		Return
	
	If (m = Mouse1) { ; 720953
		MouseMove, %x%, %y%, 0, r
		MouseGetPos, x, y
		Click(x, y, b)
	} Else If (m = Mouse2) { ; 18416789
		Mouse(x, y, b)
	}
	Return
}

Mouse(xo, yo, b=0) {
	Static x, y
	x += xo ;/ 1.75
	y += yo ;/ 1.75
	If (x < 0)
		x := 0
	Else If (x > A_ScreenWidth - 1)
		x := A_ScreenWidth - 1
	If (y < 0)
		y := 0
	Else If (y > A_ScreenHeight - 1)
		y := A_ScreenHeight - 1
	Gui, Show, x%x% y%y% NA
	If b
		Click(x, y, b)
	Return
}

Click(x, y, b=1) {
	hwnd := DllCall("WindowFromPoint", "Int", x - 1, "Int", y - 1)
	WinGetPos, WinX, WinY,,, Ahk_ID %hwnd%
	x -= winx
	y -= winy
	
	If b = 1
	{
		b = left
		d = down
	}
	else if b = 2
	{
		b = left
		d = up
	}
	else if b = 4
	{
		b = right
		d = down
	}
	else if b = 8
	{
		b = right
		d = up
	}
	else if b = 5
	{
		b = left
		d = down
		ControlClick, x%X% y%Y%, Ahk_ID %hwnd%, , %B%, 1, %D%
		b = right
	}
	else if b = 10
	{
		b = left
		d = up
		ControlClick, x%X% y%Y%, Ahk_ID %hwnd%, , %B%, 1, %D%
		b = right
	}
	else
		Return
	
	ControlClick, x%X% y%Y%, Ahk_ID %hwnd%, , %B%, 1, %D%
	Return
}

OLD: ------------------------------------------------------------------------------

Here is my clumsy second cursor movement script based on this thread.
I got the idea from fps-games, how they reset your mouse to the middle and track your movements and stuff.

CoordMode, Mouse, Screen

Gui, color, 000000
Gui, -Caption +AlwaysOnTop
Gui, show, w30 h30 x0 y0, luuu
WinSet, Region, 5-10 0-10 0-0, luuu
Return

#If GetKeyState("RButton", "P")

LButton::
hwnd := dllcall("WindowFromPoint", "Int", x, "Int", y)
WinGetPos, WinX, WinY,,, Ahk_ID %hwnd%
controlclick, % "x" x - winx " y" y - winy, Ahk_ID %hwnd% ; ,,,, NA
return

#If

RButton::
MouseGetPos, OX, OY
While (GetKeyState("RButton", "P") = 1) {
	MouseGetPos, X1, Y1
	Sleep, 1
	MouseGetPos, X2, Y2
	Mouse2(X2 - X1, Y2 - Y1)
	MouseMove, OX, OY, 0
}
Return

Mouse2(nx, ny) {
	Global
	X += nx * 2
	Y += ny * 2
	WinMove, luuu,, %x%, %y%
}

Esc::ExitApp

I found a better solution. It uses AHKHID.
Capslock to toggle which mouse is in use.

#Include AHKHID.ahk
CoordMode, Mouse, Screen
Global Toggle

Gui, Color, Black
Gui, -Caption +AlwaysOnTop +ToolWindow +LastFound
Gui, show, w30 h30 x0 y0, luuu
WinSet, Region, 0--1 0-16 1-16 5-12 7-12 11-12 11-10, luuu
GuiHandle := WinExist()
Gui, Show

SetFormat, FloatFast, 3.0

AHKHID_UseConstants()
OnMessage(0x00FF, "InputMsg")
AHKHID_Register(1, 2, GuiHandle, RIDEV_INPUTSINK)
Return

Capslock::
Toggle := !Toggle
If Toggle
	BlockInput, MouseMove
Else
	BlockInput, MouseMoveOff
Return

#If Toggle

LButton::
Mouse(0, 0, "Left", "Down")
Return

LButton Up::
Mouse(0, 0, "Left", "Up")
Return

RButton::
Mouse(0, 0, "Right", "Down")
Return

RButton Up::
Mouse(0, 0, "Right", "Up")
Return

#If

Escape::
GuiClose:
AHKHID_Register(1, 2, 0, RIDEV_REMOVE)
ExitApp

InputMsg(wParam, lParam) {
	Local x, y
	If !Toggle
		Return
	x := AHKHID_GetInputInfo(lParam, II_MSE_LASTX)
	y := AHKHID_GetInputInfo(lParam, II_MSE_LASTY)
	If x OR y
		Mouse(x, y)
	Return
}

Mouse(xo, yo, b="", d="") {
	Static x, y
	x += xo ;/ 1.75
	y += yo ;/ 1.75
	Gui, Show, x%x% y%y% NA
	If b
		Click(x, y, b, d)
	Return
}

Click(x, y, b, d) {
	hwnd := DllCall("WindowFromPoint", "Int", x - 1, "Int", y - 1)
	WinGetPos, WinX, WinY,,, Ahk_ID %hwnd%
	x -= winx
	y -= winy
	ControlClick, x%X% y%Y%, Ahk_ID %hwnd%, , %B%, 1, %D%
	Return
}


GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009
Bump for new, awesomer script

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

Bump for new, awesomer script


Bump. Gonna try this out. If I understand ya correctly it is only one mouse at the time though?

geekdude-notloggedin
  • Guests
  • Last active:
  • Joined: --
There are two scripts, one uses 2 mice simultaneously, the other uses 1 mouse and two cursors

evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005
Awesome. I am looking for something like this for when HotkeyIt and I pair-program via TeamViewer - I have a multi-monitor setup and want to be able to look up stuff on MSDN etc on a side monitor while he is typing in code on the main monitor - hopefully this is just the ticket :)
I wonder if something similar could be rigged up for the keyboard? ie allow both of us to be coding in different apps (him writing the C code in a Visual Studio window, me writing the ahk test script in a SCITE window) at the same time?