Skip to content

Instantly share code, notes, and snippets.

@fabd
Last active May 1, 2024 00:18
Show Gist options
  • Save fabd/4ec04c6875e1e34918babd2e8f3bb04c to your computer and use it in GitHub Desktop.
Save fabd/4ec04c6875e1e34918babd2e8f3bb04c to your computer and use it in GitHub Desktop.
Guild Wars Mouselook Toggle (Autohotkey Script) - relieve the wrists by no longer having to hold the right mouse button all the time - best for solo play/questing
;
; Guild Wars Mouselook Toggle v1.2b
;
; - Toggle Mouselook with Tab key
;
; >> While Mouselook is on use the mouse wheel for Camera Zoom In/Out
;
; >> While Mouselook is on, press Interract key to select the entity in front of the character
; and automatically turn off Mouselook - very handy to loot chest, start a NPC dialogue etc.
;
; (the way this works is a left mouse click is sent at the center of the view, so typically
; you only need to be close and to face the NPC or chest or other entity to Interract with)
;
; >> When Mouselook is ON, you gain access to additional shortcuts that make it easier
; to trigger skills 5-8 (this is configurable to any in-game key bind)
;
; MouseLook + LMB activate skill on the skillbar (configure below)
; MouseLook + RMB ...
; MouseLook + Shift + LMB ...
; MouseLook + Shift + RMB ...
;
; >> When Mouselook is OFF, the Interract key sends a left click, so you can simply point to
; a chest, or NPC and press the Interract key (no extra clicks necessary)
;
; >> Chat key turns off Mouselook (configure chat key below)
;
;
; - Alt + 1,2,3 set Hero flags
;
; - Alt D to double click (useful for Salvage/Id kits)
;
; - Shift Space same as Ctrl Space, sets Pirority Target (easier to trigger on laptop
; due to the tiny fn and Ctrl keys)
;
; - Alt k /kneel
;
; - F10 toggle UI (alternative to pressing Ctrl Shift H)
;
;
; CONFIGURATION
;
; - Command_Party_Key : make sure to set to the same key bind used in game, this will
; turn off Mouse Look when placing the flag (otherwise the mouse cursor wouldn't show)
; - (recommended) set the Command Party to "g" for easy reach with left hand
; then set "Panel: Open Guild" to something else
;
;
; FEATURES
;
; Chat key turns off mouselook, check these match in-game controls:
;
; Chat_Open_Chat_Key
;
;
; When Mouselook is ON, use Mouse Wheel for Camera Zoom In/Out:
;
; Camera_Zoom_In_Key
; Camera_Zoom_Out_Key
;
;
; IDEAS
; - detect black pixels when zoning, auto turn off mouselook
;
;
;
;
#NoEnv
#SingleInstance force
SetWorkingDir %A_ScriptDir%
Menu, Tray, Icon, Guild Wars.ico
; Mouse Look Toggle key (default: Tab)
Toggle_key = Tab
; The Attack/Interract (Do It) key
Interract_Key = f
; Allows to use Shift + "Target Foe - Nearest" for "Target Foe - Next"
Target_Foe_Key = ; the in game key for "Foe - Nearest" (with "+" for Shift)
Target_Foe_Next_Key = x ; the in game key for "Foe - Next"
; Start chat key
Chat_Open_Chat_Key = Enter
;Chat_Reply_Key = Backspace
; Remap start chat command (slash) key, set both to = to disable
Remap_Slash_Key_From = : ; use = to disable remapping
Remap_Slash_Key_To = =
; Camera Zoom In/Out with the mouse wheel while Mouse Look is active
Camera_Zoom_In_Key = Numpad8
Camera_Zoom_Out_Key = Numpad5
; Make sure this matches Action: Command Party in-game, turns off Mouse Look
Command_Party_Key = g
; Command Hero Flags
Command_Hero_1_Key = Numpad1
Command_Hero_2_Key = Numpad2
Command_Hero_3_Key = Numpad3
; THIS SHOULD NOT CHANGE (see EscapeKey code below for more info) (default: Esc)
Escape_Key = Esc
; When MouseLook is active, use left/right click to activate skill 7 and 8 on the skillbar
ML_Left_Click_Key = 7
ML_Right_Click_Key = 8
; Additional mouse hotkeys available while Mouse Look is active
ML_Shift_Left_Click_Key = 5
ML_Shift_Right_Click_Key = 6
;Alt_Left_Click_Key = !Numpad1
;Alt_Right_Click_Key = !Numpad3
; Which key do you want as a shortcut to hide UI (instead of Ctrl Shift H)
Hide_UI_Key = f10
; Misc initialization (don't change these)
mouselook := 0
Hotkey,IfWinActive,ahk_class ArenaNet_Dx_Window_Class
Hotkey,%Toggle_key%,ToggleMouseLook, UseErrorLevel 2
Hotkey,%Interract_Key%,InterractKey, UseErrorLevel 2
Hotkey,%Chat_Open_Chat_Key%,ActivateChatKey, UseErrorLevel 2
Hotkey,%Remap_Slash_Key_From%,RemapSlashCommandKey, UseErrorLevel 2
Hotkey,%Escape_Key%,EscapeKey, UseErrorLevel 2
Hotkey,%Command_Party_Key%,CommandPartyKey, UseErrorLevel 2
Hotkey,%Target_Foe_Key%,TargetFoeKey, UseErrorLevel 2
Hotkey,%Hide_UI_Key%,HideUiKey, UseErrorLevel 2
; This improves Interract Key handling a little bit
SendMode Input
; -------------------------------------------------------------------------------
; Here we begin an endless loop polling the screen to detect when the player
; is zoning - in which case we turn off mouselook.
; -------------------------------------------------------------------------------
MainLoop:
Loop
{
IfWinActive, ahk_class ArenaNet_Dx_Window_Class
{
isZoningScreen := false
; Calculate the coordinates of the pixels to check
Pixel1X := WinX + 100 ; Adjust X coordinate as needed
Pixel1Y := WinY + 100 ; Adjust Y coordinate as needed
Pixel2X := WinX + 150 ; Adjust X coordinate as needed
Pixel2Y := WinY + 100 ; Adjust Y coordinate as needed
Pixel3X := WinX + 200 ; Adjust X coordinate as needed
Pixel3Y := WinY + 100 ; Adjust Y coordinate as needed
; Get the color of the pixels
PixelColor1 := PixelColorFast(100, 0)
PixelColor2 := PixelColorFast(200, 0)
PixelColor3 := PixelColorFast(300, 0)
; When zoning there is a lot of pure black background color
if (PixelColor1 = 0x000000 && PixelColor2 = 0x000000 && PixelColor3 = 0x000000)
{
isZoningScreen := true
; SoundBeep
ReleaseMlook()
Break
}
}
; Check every X milliseconds (no need to poll 60 times per second)
Sleep, 150
}
Sleep, 200
Goto, MainLoop
Return
#IfWinNotActive ahk_class ArenaNet_Dx_Window_Class
; Numpad = to resize/center desktop windows (ie. browser)
$SC059::
CenterAndResizeWindow()
Return
#IfWinActive ahk_class ArenaNet_Dx_Window_Class
ToggleMouseLook:
if (mouselook == 0)
{
mouselook := 1
DllCall("SetCursorPos", int, (A_ScreenWidth/2-4) , int, (A_ScreenHeight/2))
Send {RButton down}
Sleep, 100
Return
}
ReleaseMlook()
return
; The Interract hotkey sends a left click in the middle of the view. This allows the user
; to interract with NPCs without having to toggle off mouselook first.
InterractKey:
if (mouselook == 1)
{
ReleaseMlook()
; Handy, but sometimes annoying behaviour
Sleep, 10
Click left
Sleep, 10
Return
}
; If not using mouselook, let key through
Send {%Interract_Key%}
Return
; Release mouselook when activating chat window
ActivateChatKey:
ReleaseMlook()
Send {%Chat_Open_Chat_Key%}
Return
RemapSlashCommandKey:
ReleaseMlook()
Send {%Remap_Slash_Key_To%}
Return
; This just auto-exit mouselook (ie. right button) so we can see where to place the flag
CommandPartyKey:
ReleaseMlook()
Send {%Command_Party_Key%}
Return
; Allow to use Shift+(Targeting: Foe - Nearest) for "Targeting: Foe - Next"
TargetFoeKey:
Send {%Target_Foe_Next_Key%}
Return
; Use a single keypress instead of Ctrl Shift H to hide UI
HideUiKey:
Send ^+h
Return
; The Escape also toggles off Mouse Look. This is partly for user-friendliness, and partly
; because it solves not being able to detect the main menu (the Escape menu) in the Addon.
EscapeKey:
ReleaseMlook()
Send {%Escape_Key%}
Return
;Alt-D to double click
$!d::Click 2
; Alternative to Ctrl-Space, easier to trigger on laptop with small fn/ctrl keys
$+Space::
Send ^{Space}
Return
; /kneel shortcut
$!k::
Send /kneel{Return}
Return
; Map the LMB to Action Bar while Mouse Look is active
$LButton::
if (mouselook == 1)
{
Send {%ML_Left_Click_Key%}
Return
}
Click down left
KeyWait, LButton
Click up left
Return
; Map Shift + LMB to Action Bar while Mouse Look is active
$+LButton::
if (mouselook == 1)
{
Send {%ML_Shift_Left_Click_Key%}
Return
}
Click down left
KeyWait, LButton
Click up left
Return
; Let RMB function as normal, so we can use it in mouselook
$RButton::
; auto-exit mouselook mode
if (mouselook == 1)
{
Send {%ML_Right_Click_Key%}
Return
}
Click down right
KeyWait, RButton
Click up right
Return
; Map Shift + RMB to something while Mouse Look is active
$+RButton::
if (mouselook == 1)
{
Send {%ML_Shift_Right_Click_Key%}
Return
}
Click down right
KeyWait, RButton
Click up right
Return
; Alt + 1/2/3 Number keys (left hand) for the Command Hero flags (we cannot bind modifier keys in-game)
$!SC002::
ReleaseMlook()
Send {%Command_Hero_1_Key%}
Return
$!SC003::
ReleaseMlook()
Send {%Command_Hero_2_Key%}
Return
$!SC004::
ReleaseMlook()
Send {%Command_Hero_3_Key%}
Return
;$!LButton::
; if (mouselook == 1)
; {
; Send {%Alt_Left_Click_Key%}
; Return
; }
; Return
;$!RButton::
; if (mouselook == 1)
; {
; Send {%Alt_Right_Click_Key%}
; Return
; }
; Return
$WheelUp::
If (mouselook == 1)
{
Send, {%Camera_Zoom_In_Key%}
Return
}
Send, {WheelUp}
Return
$WheelDown::
If (mouselook == 1)
{
Send, {%Camera_Zoom_Out_Key%}
Return
}
Send, {WheelDown}
Return
; Release the Right Mouse Button when switching focus away from the game window
~!TAB::
~^!DEL::
ReleaseMlook()
Return
~LWin::
ReleaseMlook()
Send, {LWin}
Return
~RWin::
ReleaseMlook()
Send, {RWin}
Return
ReleaseMlook()
{
global mouselook
if (mouselook == 1)
{
;SoundBeep,,50
mouselook := 0
Send, {RButton UP}
}
}
; Center and resize the active application window so they overlap nicely (for wiki, etc)
CenterAndResizeWindow()
{
WinGetTitle, currentWindow, A
IfWinExist %currentWindow%
{
WinGetPos, , , win_width, win_height
If (win_width == 1600 || win_width != 1300) {
WinMove, , , (A_ScreenWidth - 1300)/2, (A_ScreenHeight - 1200)/2 - 24, 1300, 1200
}
else {
WinMove, , , (A_ScreenWidth - 1600)/2, (A_ScreenHeight - 1200)/2 - 24, 1600, 1200
}
}
}
; This is MUCH faster than PixelGetColor() because it works on the game window rather
; than the full desktop. The builtin function in Autohotkey is very slow in Windows 7
; and causes a frame rate drop because it has to go through desktop composition.
;
; Source: http://www.autohotkey.com/board/topic/38414-pixelcolorx-y-window-transp-off-screen-etc-windows/#entry242401
;
PixelColorFast(pc_x, pc_y)
{
pc_wID := GetGameWindowId()
pc_hDC := DllCall("GetDC", "UInt", pc_wID)
pc_fmtI := A_FormatInteger
SetFormat, IntegerFast, Hex
pc_c := DllCall("GetPixel", "UInt", pc_hDC, "Int", pc_x, "Int", pc_y, "UInt")
pc_c := pc_c >> 16 & 0xff | pc_c & 0xff00 | (pc_c & 0xff) << 16
pc_c .= ""
SetFormat, IntegerFast, %pc_fmtI%
DllCall("ReleaseDC", "UInt", pc_wID, "UInt", pc_hDC)
return pc_c
}
; Return unique ID of the game window.
GetGameWindowId()
{
static gameWindowId = 0
if (gameWindowId == 0)
{
gameWindowId := WinExist("ahk_class ArenaNet_Dx_Window_Class")
if (gameWindowId == 0)
{
MsgBox "GetGameWindowId() could not find game window."
exit
}
}
return gameWindowId
}
@fabd
Copy link
Author

fabd commented Apr 11, 2024

Changelog

  • v1.2 : auto turn off Mouselook when zoning - to do this poll the screen for black pixels on the loading screen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment