Jump to content

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

Un-Interrupting Second Mouse Used by Joystick


  • Please log in to reply
3 replies to this topic
CraSH23000
  • Members
  • 40 posts
  • Last active: Apr 15 2013 06:03 AM
  • Joined: 22 Jun 2007
I was playing around with http://www.autohotke...ystickMouse.htm and I thought it would be cool to make a 2nd mouse. I am trying to find away to get what window is under my second mouse so that I can do controlclicks instead of mouseclicks so that I dont have to pull the primary mouse and change active windows.

It is kind of cool and has potential but there is some obstacles.

Heres the code:

; Using a Joystick as a Mouse
; http://www.autohotkey.com
; This script converts a joystick into a three-button mouse.  It allows each
; button to drag just like a mouse button and it uses virtually no CPU time.
; Also, it will move the cursor faster depending on how far you push the joystick
; from center. You can personalize various settings at the top of the script.

; Increase the following value to make the mouse cursor move faster:
JoyMultiplier = 0.30

; Decrease the following value to require less joystick displacement-from-center
; to start moving the mouse.  However, you may need to calibrate your joystick
; -- ensuring it's properly centered -- to avoid cursor drift. A perfectly tight
; and centered joystick could use a value of 1:
JoyThreshold = 3

; Change the following to true to invert the Y-axis, which causes the mouse to
; move vertically in the direction opposite the stick:
InvertYAxis := false

; Change these values to use joystick button numbers other than 1, 2, and 3 for
; the left, right, and middle mouse buttons.  Available numbers are 1 through 32.
; Use the Joystick Test Script to find out your joystick's numbers more easily.
ButtonLeft = 1
ButtonRight = 2
ButtonMiddle = 3

; If your joystick has a POV control, you can use it as a mouse wheel.  The
; following value is the number of milliseconds between turns of the wheel.
; Decrease it to have the wheel turn faster:
WheelDelay = 250

; If your system has more than one joystick, increase this value to use a joystick
; other than the first:
JoystickNumber = 1

; END OF CONFIG SECTION -- Don't change anything below this point unless you want
; to alter the basic nature of the script.
MouseGetPos, xval, yval

CoordMode,Mouse, Screen

SplashImage, mouse_clone.jpg, B X%xval% Y%yval%,,,, splash_image_title

#SingleInstance

JoystickPrefix = %JoystickNumber%Joy
Hotkey, %JoystickPrefix%%ButtonLeft%, ButtonLeft
Hotkey, %JoystickPrefix%%ButtonRight%, ButtonRight
Hotkey, %JoystickPrefix%%ButtonMiddle%, ButtonMiddle


; Calculate the axis displacements that are needed to start moving the cursor:
JoyThresholdUpper := 50 + JoyThreshold
JoyThresholdLower := 50 - JoyThreshold
if InvertYAxis
	YAxisMultiplier = -1
else
	YAxisMultiplier = 1

SetTimer, WatchJoystick, 10  ; Monitor the movement of the joystick.

GetKeyState, JoyInfo, %JoystickNumber%JoyInfo
IfInString, JoyInfo, P  ; Joystick has POV control, so use it as a mouse wheel.
	SetTimer, MouseWheel, %WheelDelay%

return  ; End of auto-execute section.


; The subroutines below do not use KeyWait because that would sometimes trap the
; WatchJoystick quasi-thread beneath the wait-for-button-up thread, which would
; effectively prevent mouse-dragging with the joystick.

ButtonLeft:
MouseGetPos, xmval, ymval
xclkspot := xval-1
yclkspot := yval-1
MouseClick, left,%xclkspot%, %yclkspot%, 1, 0
SetMouseDelay, 10
MouseMove, %xmval%, %ymval%, 0
return

ButtonRight:
MouseGetPos, xmval, ymval
xclkspot := xval-1
yclkspot := yval-1
MouseClick, Right,%xclkspot%, %yclkspot%, 1, 0
SetMouseDelay, 10
MouseMove, %xmval%, %ymval%, 0
return

ButtonMiddle:
MouseGetPos, xmval, ymval
xclkspot := xval-1
yclkspot := yval-1
MouseClick, Middle,%xclkspot%, %yclkspot%, 1, 0
SetMouseDelay, 10
MouseMove, %xmval%, %ymval%, 0
return



WatchJoystick:
MouseNeedsToBeMoved := false  ; Set default.
SetFormat, float, 03
GetKeyState, joyx, %JoystickNumber%JoyX
GetKeyState, joyy, %JoystickNumber%JoyY
if joyx > %JoyThresholdUpper%
{
	MouseNeedsToBeMoved := true
	DeltaX := joyx - JoyThresholdUpper
}
else if joyx < %JoyThresholdLower%
{
	MouseNeedsToBeMoved := true
	DeltaX := joyx - JoyThresholdLower
}
else
	DeltaX = 0
if joyy > %JoyThresholdUpper%
{
	MouseNeedsToBeMoved := true
	MouseNeedsToBeMovedup := true
	DeltaY := joyy - JoyThresholdUpper
}
else if joyy < %JoyThresholdLower%
{
	MouseNeedsToBeMoved := true
	DeltaY := joyy - JoyThresholdLower
}
else
	DeltaY = 0
if MouseNeedsToBeMoved
{
	
	xval := xval + DeltaX * JoyMultiplier
	yval := yval + DeltaY * JoyMultiplier * YAxisMultiplier

	SplashImage, Off
	SplashImage, mouse_clone.jpg, B X%xval% Y%yval%,,,, splash_image_title
}
return


I have a .rar so that it will work because of the image for the 2nd mouse

Download Mouse_Clone.rar

EDIT: 7-zip requested: Download Mouse_Clone.7z
Thanks to "Guest" for telling me about .7z, looks like thy compress even smaller than .rar

Thanks for any advise or criticism.
Truth is truth, whether you believe it or not.

  • Guests
  • Last active:
  • Joined: --

I have a .rar...

...grrrrr!...can I PLEASE beg people to stop posting .rar's?...if you can make a .rar, you can make a .zip...or even better make a .7z...

CraSH23000
  • Members
  • 40 posts
  • Last active: Apr 15 2013 06:03 AM
  • Joined: 22 Jun 2007
Changed top post to include a .7z. I only used .rar because they compress better than .zip but its nice that .7z compresses even smaller than .rar. :p
Truth is truth, whether you believe it or not.

GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009
i do have something to say,, you can use these instead of all those ;

In addition, the /* and */ symbols can be used to comment out an entire section, but only if the symbols appear at the beginning of a line as in this example:

/*
MsgBox, This line is commented out (disabled).
MsgBox, This one too.
*/


<!-- m -->http://www.autohotke...ts.htm#Comments<!-- m --> :)