Last active
July 1, 2024 13:27
-
-
Save ZerothAngel/03469595da8616bc76871448038ce022 to your computer and use it in GitHub Desktop.
Mouselook AutoHotKey script that inverts the right mouse button when toggled on. Very useful for MMOs that lack an action-mouselook mode. As-is, it works with FFXIV but can be easily adapted by correctly setting the ahk_class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance force | |
#NoEnv | |
SendMode Input | |
; Keybinds | |
AutoCenterToggle := "RWin" | |
MouseLook := "RButton" | |
; Config | |
CenterOffsetX := 100 | |
CenterOffsetY := 0 | |
; State | |
MouseLookState := false ; true if RMB is currently inverted | |
ManualMouseLookState := false ; For keeping track of physical RMB state (when not inverted) | |
AutoCenterState := false | |
MouseLookCounter := 0 ; Send RMB down on 0 -> 1 only, similarly RMB up on 1 -> 0 only | |
SetCapsLockState, Off | |
Hotkey, IfWinActive, ahk_class FFXIVGAME | |
HotKey, *$%AutoCenterToggle%, ToggleAutoCenter | |
HotKey, *$%MouseLook%, ManualMouseLookDown | |
HotKey, *$%MouseLook% Up, ManualMouseLookUp | |
HotKey, CapsLock, ToggleMouseLook | |
return | |
CenterMouse: | |
if (AutoCenterState && !ManualMouseLookState) | |
{ | |
BlockInput, Mousemove | |
WinGetPos,,,WinWidth,WinHeight,ahk_class FFXIVGAME | |
MouseMove,CenterOffsetX+WinWidth/2,CenterOffSetY+WinHeight/2,1 | |
BlockInput, MouseMoveOff | |
} | |
return | |
ToggleMouseLook: | |
if (MouseLookState) | |
{ | |
gosub, SendMouseLookUp | |
} | |
else | |
{ | |
gosub, CenterMouse | |
gosub, SendMouseLookDown | |
} | |
MouseLookState := !MouseLookState | |
SetCapsLockState, Off | |
return | |
ToggleAutoCenter: | |
AutoCenterState := !AutoCenterState | |
return | |
ManualMouseLookDown: | |
if (MouseLookState) | |
{ | |
; Currently inverted, so "release" mouselook | |
gosub, SendMouseLookUp | |
} | |
else | |
{ | |
; Not currently inverted, just behave normally | |
gosub, SendMouseLookDown | |
; But also keep track of this click | |
ManualMouseLookState := true | |
} | |
return | |
ManualMouseLookUp: | |
if (MouseLookState) | |
{ | |
gosub, CenterMouse | |
; Currently inverted, re-enable mouselook | |
gosub, SendMouseLookDown | |
} | |
else | |
{ | |
; Not currently inverted, just behave normally | |
gosub, SendMouseLookUp | |
} | |
ManualMouseLookState := false | |
return | |
SendMouseLookDown: | |
; Send only on edge between 0 -> 1 | |
if (++MouseLookCounter == 1) | |
{ | |
send {%MouseLook% down} | |
} | |
MouseLookCounter := Min(MouseLookCounter, 1) ; Saturate at 1 | |
return | |
SendMouseLookUp: | |
; Send only on edge between 1 -> 0 | |
if (--MouseLookCounter == 0) | |
{ | |
send {%MouseLook% up} | |
} | |
MouseLookCounter := Max(MouseLookCounter, 0) ; Sanity | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I originally stumbled upon this script over a decade ago, apologies to the original author(s) whom I've forgotten. I've pretty much adapted & used it for every MMO I've played since then (SWTOR, The Secret World, FFXIV, GW2 before it gained an action camera, Wildstar, etc.). I've also enhanced it quite a bit, adding optional auto-centering and true RMB inversion (i.e. RMB will release if you physically press RMB, making it easier to do mouseover aiming).
As-is, use caps lock to toggle the inversion state on & off and right-WinKey to toggle auto-centering. Modify the hotkeys to taste.