Thursday, July 28, 2016

Found a way to change the XY mouse input into aswd (or in my case asdf)!

1. Download Autohotkey. https://autohotkey.com/
2. Install Autohotkey.
3. Run Autohotkey (must be in the background for this following script to run).
4. Open Notepad.
5. Copy the following text into said textpad.

;==========================================================================
;
; MouseSendZones
;
; Author: Pulover [Rodolfo U. Batista]
; rodolfoub@gmail.com
;
; Description: This 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.
;
;==========================================================================

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

; Select Hotkey to active the funtion:
Activate =\

; Select Hotkey show Zones Guidelcines:
ShowZones = [

; Select optional Hotkey reset mouse to Center:
Center =]
; Set Horizontal & Vertical Dead Zone Ranges in pixels:
DeadZoneRangeX := 150
DeadZoneRangeY := 115

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

; ########## 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 the coordinates for the center of the screen to create a Dead Zone:
DeadZoneX := A_ScreenWidth / 2
DeadZoneY := A_ScreenHeight / 2

; Activate Hotkeys:
Hotkey, %Activate%, Activate, 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

Activate:
SetTimer, WatchMouse, % (Active := !Active) ? 0 : "Off"
Loop, % %hKeys%0
Send, %  (hKeys = "DeadZone") ? "" : "{" %hKeys%%A_Index% " up}"
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
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 .= "Right"
If (X < (DX - RX))
Zone .= "Left"
return Zone = "" ? "DeadZone" : Zone
}
;==========================================================================
; ALT-F3 remaximizes Halo Spartan Assault
;==========================================================================

!F3:: ;Maximize/Restore Window
WinGet MX, MinMax, A
If MX
WinRestore A
Else WinMaximize A
return

;==========================================================================
; End of Script
;==========================================================================

6. Edit the name of this script "mouse to keypress.txt" to "mouse to keypress.ahk"
If you cannot edit the .txt to turn it to a .ahk then do the following:
6a. Click the Start menu. ...
6b. Type "folder options" (without the quotes). ...
6c.  A dialog box with the title "Folder Options" will appear. ...
6d. Click to uncheck the box for "Hide extensions for known file types".
6f.  Click the "OK" button at the bottom of the dialog box.
7. Double click on "mouse to keypress.ahk". (Now it's in memory!)
8. Press the '\' key. This will turn this script on and off (as long as autohotkey is running in the background)
9. Press the '[' key. A red box will appear. Move your mouse cursor outside this box and it will keep press a,s,d, or f (or whatever else keys you

assigned instead of asdf like I did). In other words, the dog runs out of the red fence, a keyboard key is pressed for that side.
10. Press the ']' Key. This will center your mouse cursor to this red box.
11. Optional. If you don't want Autohotkey to be running in the background, then select "compile script'. This will turn your "mouse to

keypress.ahk" into a "mouse to keypress.exe"