Jump to content

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

Mouse Movement to Keypress


  • Please log in to reply
49 replies to this topic
chrisb114
  • Members
  • 8 posts
  • Last active: Nov 11 2015 08:56 PM
  • Joined: 21 Feb 2013
 


You'll have edit this part:

; Get the coordinates for the center of the screen to create a Dead Zone:DeadZoneX := A_ScreenWidth / 2DeadZoneY := A_ScreenHeight / 2
 
Thanks i like just found it befor i came back. One last thing can the deadzone be made a circle?

Pulover
  • Members
  • 1596 posts
  • Last active: Apr 06 2016 04:00 AM
  • Joined: 20 Apr 2012

  
Thanks i like just found it befor i came back. One last thing can the deadzone be made a circle?

Not by me, pal... sorry, too complicated.

Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer) | Class_LV_Rows - Copy, Cut, Paste and Drag ListViews | Class_Toolbar - Create and modify | Class_Rebar - Adjustable GUI controls

Join the New AutoHotkey Forum!


chrisb114
  • Members
  • 8 posts
  • Last active: Nov 11 2015 08:56 PM
  • Joined: 21 Feb 2013

No problem thank you answering me.



swallis7
  • Members
  • 6 posts
  • Last active: Jun 17 2016 09:44 PM
  • Joined: 22 Apr 2014
;==========================================================================
;
; 				MouseSendZones
;
; Author:		Pulover [Rodolfo U. Batista]
;				[email protected]
;
; HoverMode:	The script sends user-defined keys when the mouse is
;		over an area of the screen by creating a rectangle at
;		the center to be the Dead Zone and 8 other rectangles
;		around it, each one will send and hold the configured
;		keys when the mouse hovers over it.
;
; StickMode:	When the mouse is moved in one direction the script
;		sends the corresponding keys and releases them when
;		it stops moving. This is more specific for using a
;		joystick to control mouse movements.
;
;==========================================================================

; ########## Configurations: ##########

; Select Hotkey to active HoverMode:
Hover = ~F1

; Select Hotkey to active StickMode:
Stick = ~F2

; Select Hotkey show Zones Guidelines:
ShowZones = CapsLock

; Select optional Hotkey reset mouse to Center:
Center = MButton

; Set Horizontal & Vertical Dead Zone Ranges in pixels:
DeadZoneRangeX := 200
DeadZoneRangeY := 150

KeySet =
( ; Set the keys that will be sent for each of the eight zones of the screen:
Up = Up
Down = Down
Left = Left
Right = Right
UpLeft = Up & Left
UpRight = Up & Right
DownLeft = Down & Left
DownRight = Down & Right
)

; ########## End of configurations! ##########

; Parse KeySet and assign variables to the keys:
Loop, Parse, KeySet, `n
{
	Loop, Parse, A_LoopField, =, %A_Space%
		If Mod(A_Index, 2)
			Key := A_LoopField
		Else
		{
			%Key% := A_LoopField
			StringSplit, %Key%, A_LoopField, &, %A_Space%
		}
}

#SingleInstance, Force
SendMode, Input
SetKeyDelay, -1
SetMouseDelay, -1
SetBatchLines, -1 ; How often the script should sleep (how fast it will run)
CoordMode, Mouse, Screen

; Get coordinates for the center of the screen to create a Dead Zone:
DeadZoneX := A_ScreenWidth / 2
DeadZoneY := A_ScreenHeight / 2

; Activate Hotkeys:
Hotkey, %Hover%, Hover, On
Hotkey, %Stick%, Stick, On
Hotkey, %ShowZones%, ShowZones, On
Try Hotkey, %Center%, CenterMouse, On

; Create a rectangle to show Dead Zone:
A := DeadZoneRangeX*2, B := DeadZoneRangeY*2, C := A-2, D := B-2

Gui, -Caption +ToolWindow +LastFound +AlwaysOnTop
Gui, Color, Red
Gui, +LastFound
WinSet, Region, 0-0 %A%-0 %A%-%B% 0-%B% 0-0  2-2 %C%-2 %C%-%D% 2-%D% 2-2
GoSub, ShowZones
Display := !Display
SetTimer, RemoveTip, -1500
return

Hover:
StickMode := False
SetTimer, WatchMouse, % (HoverMode := !HoverMode) ? 0 : "Off"
Loop, % %hKeys%0
	Send, %  (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
TrayTip,, % (HoverMode) ? "HoverMode On" : "HoverMode Off"
return

Stick:
HoverMode := False
SetTimer, WatchMouse, % (StickMode := !StickMode) ? 0 : "Off"
Loop, % %hKeys%0
	Send, %  (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
TrayTip,, % (StickMode) ? "StickMode On" : "StickMode Off"
return

ShowZones:
If (Display := !Display)
{
	Gui, Show, % "NA x" DeadZoneX - DeadZoneRangeX "y" DeadZoneY - DeadZoneRangeY "w" DeadZoneRangeX * 2 "h" DeadZoneRangeY * 2
	Tooltip, Dead Zone, % DeadZoneX-25, % DeadZoneY-25, 1
	Tooltip, % Up, % DeadZoneX-25, % 0, 2
	Tooltip, % Down, % DeadZoneX-25, % A_ScreenHeight, 3
	Tooltip, % Left, % 0, % DeadZoneY-25, 4
	Tooltip, % Right, % A_ScreenWidth, % DeadZoneY-25, 5
	Tooltip, % UpLeft, % 0, % 0, 6
	Tooltip, % UpRight, % A_ScreenWidth, % 0, 7
	Tooltip, % DownLeft, % 0, % A_ScreenHeight, 8
	Tooltip, % DownRight, % A_ScreenWidth, % A_ScreenHeight, 9
}
Else
	GoSub, RemoveTip
return

RemoveTip:
Gui, Cancel
Tooltip,,,,1
Tooltip,,,,2
Tooltip,,,,3
Tooltip,,,,4
Tooltip,,,,5
Tooltip,,,,6
Tooltip,,,,7
Tooltip,,,,8
Tooltip,,,,9
return

CenterMouse:
Click, %DeadZoneX%, %DeadZoneY%, 0
return

WatchMouse:
MouseGetPos, pX, pY
If StickMode
{
	If ((pX = 0) || (pX = A_ScreenWidth-1))
		|| ((pY = 0) || (pY = A_ScreenHeight-1))
		GoSub, CenterMouse
	Sleep, 150
	MouseGetPos, cX, cY
	zKeys := MoveZone(pX, pY, cX, cY)
}
Else
	zKeys := GetZone(pX, pY, DeadZoneX, DeadZoneY, DeadZoneRangeX, DeadZoneRangeY)
If (hKeys <> zKeys)
{
	Loop, % %hKeys%0
		Send, %  (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
	Loop, % %zKeys%0
		Send, % (zKeys = "DeadZone") ? "" : "{" %zKeys%%A_Index% "  down}"
	hKeys := zKeys
}
return

GetZone(X, Y, DX, DY, RX, RY)
{
	If (Y < (DY - RY))
		Zone .= "Up"
	If (Y > (DY + RY))
		Zone .= "Down"
	If (X < (DX - RX))
		Zone .= "Left"
	If (X > (DX + RX))
		Zone .= "Right"
	return Zone = "" ? "DeadZone" : Zone
}

MoveZone(pX, pY, cX, cY)
{
	If (cY < pY)
		Zone .= "Up"
	If (cY > pY)
		Zone .= "Down"
	If (cX < pX)
		Zone .= "Left"
	If (cX > pX)
		Zone .= "Right"
	return Zone = "" ? "DeadZone" : Zone
}

Pulover,

The video game Planet Of The Apes has no mouse support.  I'm trying to get the mouse to 'look around', and your script is the only one I found that works.  Clicking the middle mouse button also works.

 

I wanted to add left and right mouse button clicks to it.  When I try adding "RButton::f" in the Configurations section, it works but none of the other mouse movements work any more!  How can I add the mouse button clicks?



evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005
Michigraf, check your PMs, I replied to you with some code that shows how to control a joystick with the mouse.

Mine is very basic, but if you took my code and merged it with the code I saw above that divides the screen into 9 squares, that would probably be the best solution.