AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Second Mouse Cursor (Alpha)
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
friese
Guest





PostPosted: Wed Apr 08, 2009 1:00 am    Post subject: Second Mouse Cursor (Alpha) Reply with quote

here is a very buggy script, makes lot of problems, but its cool, it creates a second mouse curosr completely independent form the original and controls it via numpad:

Code:
#persistent


gui, color, 000000
gui -Caption -sysmenu
gui, show, w30 h30 x0 y0, luuu
WinSet, Region, 5-10 0-10 0-0, luuu
winset, alwaysontop, on, luuu
speed = 30
return



Numpad8::
y -= speed
gosub reload
return

Numpad2::
y += speed
gosub reload
return

Numpad4::
x -= speed
gosub reload
return

Numpad6::
x += speed
gosub reload
return



Numpad5::
gosub reload
hwnd := dllcall("WindowFromPoint", "Int", x, "Int", y)
wingetpos, winx, winy,,, ahk_id %hwnd%
temp1 := x - winx
temp2 := y - winy
controlclick, x%temp1% y%temp2%, ahk_id %hwnd%,,,, NA
return


reload:
winset, alwaysontop, on, luuu
xt := x - 1
yt := y - 1
winmove, luuu,, %xt%, %yt%
return

have fun, i know its very crappy, but it works (a bit...)
Back to top
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Wed Apr 08, 2009 4:19 pm    Post subject: Reply with quote

Interesting idea. What inspired you to make it?
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Apr 08, 2009 6:10 pm    Post subject: Reply with quote

i wanted to control vlc on my second tft while playing 3d games in fullscreen, and because that works enough fr me it got te way i n my autostart flder
Back to top
Bingo324_NLI
Guest





PostPosted: Thu Apr 09, 2009 7:59 am    Post subject: Second mouse thing Reply with quote

Cool and interesting concept. I will use this. I'll also try and refine it too, so you get less bugs.
Back to top
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Fri Apr 10, 2009 1:25 pm    Post subject: Reply with quote

The idea of a gui for mouse and use of WindowFromPoint is really great Smile
I experimented a little and created a multiple mouse script
MultiMouse wrote:
You can define up to 20 MouseHotkeys each hotkey will have its own mouse cursor and will be shown on press and hold of that hotkey.
MoveHotkey (KeyDown, KeyLeft...) get activated when one of MouseHotkeys is pressed and deactivated when it releases.
So you need to hold your MouseHotkey and press MoveHotkey to Move the mouse.
Releasing the MouseHotkey will do the controlclick at its coordinates (this will happen only if the mouse was moved too)
Each Mousehotkey can have its own speed, startdelay and color! (you can specify as many as you like 1-20)

All MoveHotkeys are activated uppon press of MouseHotkey!
After moving and releasing MouseHotkey, you can press MouseHotkey again to click and activate that window as well.


! Note ! some of the examples are only to show the effect of value, you definitely should change it to your needs
I hope you find it useful

Code:
MainHotkey=      ~LWin|~<^RAlt|~CapsLock|~<^<Alt|Numpad0|NumpadDot

;!!!   the higher the value the slower mouse will move   !!!
speed=         2.5|5|7|10|20|50
startdelay=      30|10|20|40|10|100

color=         0000FF|FF0000|00FF00|AA55EE|EEFF00|553344

KeyUp=          w|Numpad8
KeyDown=        s|Numpad2
KeyLeft=        a|Numpad4
KeyRight=       d|Numpad6
KeyUpLeft=      Numpad7
KeyUpRight=     Numpad9
KeyDownLeft=    Numpad1
KeyDownRight=   Numpad3
Exit=           Escape

;=======================================================================================
#persistent
#MaxHotkeysPerInterval,1000
SetWinDelay,0
SetBatchLines,-1
CoordMode,ToolTip,Screen
CoordMode,Mouse,Screen
StringSplit,color,color,|
StringSplit,speed,speed,|
StringSplit,startdelay,startdelay,|
keys=KeyUp|KeyDown|KeyLeft|KeyRight|KeyUpLeft|KeyUpRight|KeyDownLeft|KeyDownRight
Loop,Parse,MainHotkey,|
{
   hotkeyvar:=RegExReplace(A_LoopField,"\<|\>|\*|\$|\^|\!|\+|\~")
   Hotkey,$%A_LoopField%,Main,UseErrorLevel
   If ErrorLevel
      MsgBox You cannot use HotKey: $%A_LoopField%`nProgram will not work if this is the only Main hotkey
   else
      %hotkeyvar%:=A_Index
}
return

Main:
mainhotkey:=A_ThisHotkey
thishotkey:=RegExReplace(A_ThisHotkey,"\>|\<|\*|\$|\^|\!|\+|\~")
Tooltip:=%thishotkey% ;assign number of tooltip
Loop,Parse,keys,|
   Loop,Parse,%A_LoopField%,|
      Hotkey,% "$*" A_LoopField,Move,On
Hotkey,*%Exit%,Exit,On
If !x%Tooltip%
   ToolTip % "   `n`n",% A_ScreenWidth/2,% A_ScreenHeight/2,%ToolTip%
else
   ToolTip % "   `n`n",% x%ToolTip%,% y%ToolTip%,%ToolTip%
tthwnd:=WinExist("ahk_class tooltips_class32")
WinSet, Region, 1-4 15-18 9-18 13-27 10-28 5-19 1-23, ahk_id %tthwnd%
WinSet,ExStyle,^0x20,ahk_id %tthwnd%
SetToolTipColor(tthwnd,!color%ToolTip% ? color1 : color%ToolTip%)
speed:=!speed%ToolTip% ? speed1 : speed%ToolTip%
startdelay:=!startdelay%ToolTip% ? startdelay1 : startdelay%ToolTip%
KeyWait,%thishotkey%
If InStr(mainhotkey,"~")
   Send, {%thishotkey% Up}
Loop,Parse,keys,|
   Loop,Parse,%A_LoopField%,|
      Hotkey,% "$*" A_LoopField,Move,Off
Hotkey,*%Exit%,Exit,Off
If MouseMoved
{
   wingetpos, winx, winy,,,% "ahk_id " . hwnd:=Dllcall("WindowFromPoint", "Int", x%ToolTip%, "Int", y%ToolTip%)
   KeyWait,%thishotkey%, D T0.15
   ErrorLevel_:=ErrorLevel
   KeyWait,%thishotkey%
   If ErrorLevel_
      ControlClick,% "x" . (x%ToolTip%+1 - winx) . " y" . (y%ToolTip%+5 - winy), ahk_id %hwnd%,,,, NA
   else {
      WinActivate,ahk_id %hwnd%
      WinWaitActive,ahk_id %hwnd%,,0.1
      MouseClick,Left,% (x%ToolTip%+1),% (y%ToolTip%+5)
   }
}
else if !InStr(mainhotkey,"~")
   Send, {%thishotkey%}
ToolTip,,,,%ToolTip%
MouseMoved=
Return

Move:
MouseMoved:=True
WinGetPos,x%ToolTip%,y%ToolTip%,,,ahk_id %tthwnd%
SysGet,xmin,76
SysGet,xmax,78
SysGet,ymin,77
SysGet,ymax,79
Loop
{
   i:=Round(A_Index/speed)
   Loop,Parse,keys,|
   {
      key:=A_LoopField
      Loop,Parse,%A_LoopField%,|
      {
         If GetKeyState(A_LoopField,"P"){
            IfInString,key,Up
               y%ToolTip%-=(y%ToolTip%-i)<=ymin ? 0 : i
            IfInString,key,Down
               y%ToolTip%+=(y%ToolTip%+i)>=ymax ? 0 : i
            IfInString,key,Left
               x%ToolTip%-=(x%ToolTip%-i)<=xmin ? 0 : i
            IfInString,key,Right
               x%ToolTip%+=(x%ToolTip%+i)>=xmax ? 0 : i
            stopbreak:=1
         }
      }
   }
   If !stopbreak
      Break
   stopbreak=
   WinMove,ahk_id %tthwnd%,,% x%ToolTip%,% y%ToolTip%
   Sleep % (startdelay-i) > 1 ? Round(startdelay-i) : 1
}
Return

SetToolTipColor(hwnd,B){
   B := (StrLen(B) < 8 ? "0x" : "") . B
   B := ((B&255)<<16)+(((B>>8)&255)<<8)+(B>>16) ; rgb -> bgr
   DllCall("SendMessage", "Uint", hWnd, "Uint", 1043, "Uint", B, "Uint", 0)   ; TTM_SETTIPBKCOLOR   
}

exit:
ExitApp

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink


Last edited by HotKeyIt on Fri Apr 10, 2009 6:24 pm; edited 4 times in total
Back to top
View user's profile Send private message
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Fri Apr 10, 2009 4:29 pm    Post subject: Reply with quote

That's really neat... but I found the way it clicks a little confusing.

Anyway, here's my contribution, prettier (and more accurate) cursors:
Code:
If !x%Tooltip%
   ToolTip % "   `n`n",% A_ScreenWidth/2,% A_ScreenHeight/2,%ToolTip%
else
   ToolTip % "   `n`n",% x%ToolTip%,% y%ToolTip%,%ToolTip%
tthwnd:=WinExist("ahk_class tooltips_class32")
WinSet, Region, 1-4 15-18 9-18 13-27 10-28 5-19 1-23, ahk_id %tthwnd%

That section comes 8 lines after "Main:".
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Fri Apr 10, 2009 6:00 pm    Post subject: Reply with quote

Thats really nice, thanks ManaUser, i've updated my script.
I also changed to wait only for 150 ms for second click (this is to activate the window on click) Wink

EDIT:
I have changed my script to do a true click when after releasing MouseHotkey it is pressed again (within 150 ms).
I have also added WinSet,ExStyle,^0x20, otherwise tooltip is found at this coordinates.
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
etopsirhc



Joined: 12 Mar 2008
Posts: 62
Location: OR

PostPosted: Mon Apr 20, 2009 5:14 am    Post subject: Reply with quote

AWESOME!!!! as soon as i get my other comp working i'm adding a second mouse on my xbox controler Razz
_________________
life is but a dream
death is the reality
Back to top
View user's profile Send private message Visit poster's website
CraSH23000



Joined: 22 Jun 2007
Posts: 40

PostPosted: Mon Apr 20, 2009 5:30 am    Post subject: Reply with quote

I tried this a while back but I did not spend that much time on it. I always wanted to be able to have 2 people using the same computer via 2 mice.

The primary difference is I made mine based on joystick input instead of the numpad.

The post I made: Un-Interrupting Second Mouse Used by Joystick

Awesome to see that I'm not the only one that shows interest in this.
Back to top
View user's profile Send private message
Madd0g_
Guest





PostPosted: Thu Oct 22, 2009 10:39 am    Post subject: Reply with quote

Would be really cool if the second cursor could be moved by the mouse as well

Instead of holding the win-key to control the other cursor with the keyboard - the modifier key would just switch the mouse control from one cursor to another.

Is it possible at all?

Thanks
Back to top
geekdude



Joined: 23 Nov 2009
Posts: 64

PostPosted: Fri Nov 27, 2009 10:52 pm    Post subject: Reply with quote

i am using 2nd cursor now... fixed the clicking so it will move the mouse back to original position

Code:
      blockinput, on
      mousegetpos, newvariablex, newvariabley
      WinActivate, ahk_id %hwnd%
      WinWaitActive, ahk_id %hwnd%,,0.1
      MouseClick, Left, % (x%ToolTip%+1), % (y%ToolTip%+5),, 0
      mousemove, %newvariablex%, %newvariabley%, 0
      blockinput, off

_________________
  /\ /\ This is Kitty
(>';'<) Cut, copy, and paste kitty onto your sig.
((")(")) Help Kitty gain World Domination.

(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Sat Nov 28, 2009 12:00 am    Post subject: Reply with quote

Madd0g_ wrote:
Would be really cool if the second cursor could be moved by the mouse as well

Instead of holding the win-key to control the other cursor with the keyboard - the modifier key would just switch the mouse control from one cursor to another.

Is it possible at all?

Thanks


Try this, MasterHotkey + [0-9] will restore mouse position and save latest position:
Code:
MasterHotkey=LWin
Hotkey,% "~" MasterHotkey,Master
MouseGetPos,X_0,Y_0
Loop 10
   Hotkey,% "*" . A_Index-1,Change,Off
last:=0
Loop 10
{
   X_%A_Index%:=A_ScreenWidth/2
   Y_%A_Index%:=A_ScreenHeight/2
}
Master:
Loop 10
   Hotkey,% "*" . A_Index-1,On
KeyWait,% SubStr(A_ThisHotkey,2)
Loop 10
   Hotkey,% "*" . A_Index-1,Off
Return

Change:
Hotkey:=SubStr(A_ThisHotkey,2)
MouseGetPos,X,Y
X_%last%:=X
Y_%last%:=Y
MouseMove,% X_%Hotkey%,% Y_%Hotkey%,0
last:=Hotkey
Return

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
Stefan VV
Guest





PostPosted: Sun Dec 06, 2009 5:21 am    Post subject: Reply with quote

I have an idea. If you have two mouses make the script get the pid's of each mouse and make a script that allows you to move your second cursor with the second mouse.

Anyway great script.
Back to top
Madd0g
Guest





PostPosted: Tue Dec 08, 2009 3:06 pm    Post subject: Reply with quote

HotKeyIt wrote:

Try this, MasterHotkey + [0-9] will restore mouse position and save latest position...


That's really nice! Thanks!
Back to top
RIST



Joined: 08 May 2008
Posts: 39
Location: C:\ESTONIA\adavere\RIST.rar

PostPosted: Wed Dec 09, 2009 2:47 pm    Post subject: Reply with quote

is any second mouse script for windows7 ?
_________________
Keegi Siin ka Eestlane? Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group