So here's a new version with both Hover and Stick methods. You can switch between them using hotkeys.
One thing I cannot figure out how it would work: move the mouse to send keystrokes but still avoid camera movements... this seems rather illogical to me. Or does anyone know how this is possible?
Let me know how it goes now.
;==========================================================================
;
; 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 Guidelcines:
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
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
}