; This script is for AutoHotkey https://autohotkey.com/download/ ; It only works if GW2 isn't running as administrator. Don't run GW2 as administrator! ; ; It has the following feature for GW2: ; ; 1. Prevent minimzing the game if you have a multi-monitor setup and are running GW2 fullscreen. ; GW2 isn't able to keep the mouse within the game very good. The script prevents that the mouse ; escapes and the minimizing of the game in the worst possible moment. It also works in windowed ; mode, where you can press ctrl to allow the mouse to leave the game area. It is also possible ; to click on the task bar to free the mouse from the game. ; ; 2. Replace pressing left Windows key with F5 (or any other key you like). Prevents droppig to ; desktop if you press WIN accidently. global CHECK_MOUSE_POS := true ; check mouse position in multi-monitor setup. Set it ; to false if you don't need this. global CHECK_MOUSE_SKIP := "Ctrl" ; modifier to press to skip mouse position check on the fly ; ------------------------------------------------------------------------------------------------- #Warn #SingleInstance, Force #NoEnv GroupAdd prog, ahk_exe gw2.exe GroupAdd prog, ahk_exe Gw2-64.exe ;GroupAdd prog, ahk_exe notepad.exe global prog_xpos, prog_ypos, prog_width, prog_height, prog_maxx, prog_maxy, prog_hwnd global MouseHook := "" global DoMouseCheck := false CoordMode Mouse, Screen CoordMode Pixel, Screen if (CHECK_MOUSE_POS) SetTimer CheckHookActive, 500 return ; Activate mousehook routine if prog becomes active and unhook it if it ; loses the focus CheckHookActive: IfWinActive ahk_group prog { if (CHECK_MOUSE_POS) { WinGet prog_hwnd ClientToScreen(prog_hwnd, prog_xpos := 0, prog_ypos := 0) GetClientRect(prog_hwnd, prog_width, prog_height) ; OutputDebug % "prog_xpos=" prog_xpos " prog_ypos=" prog_ypos " prog_width=" prog_width " prog_height=" prog_height prog_maxx := prog_xpos + prog_width prog_maxy := A_ScreenHeight if (MouseHook = "") { DoMouseCheck := false MouseHook := DllCall("SetWindowsHookEx", "int", 14 ; WH_MOUSE_LL = 14 , "Ptr", RegisterCallback("MouseProc"), "uint", 0, "uint", 0) OutputDebug % "Got focus: hooked" } ; prog is active now. Wait until it loses focus, but no longer than 0.5s. ; CheckHookActive is called again by timer, so changing window size is always recognized. WinWaitNotActive ahk_group prog, , 0.5 ifGreater, ErrorLevel, 0, return } } ; prog has no focus: unhook mouse hook, if hooked previously. if (MouseHook <> "") { DllCall("UnhookWindowsHookEx", "Ptr", MouseHook) MouseHook := "" OutputDebug % "Lost focus: unhooked" } ; nothing to do until prog has the focus again WinWaitActive ahk_group prog return ; reload this script by pressing rctrl-altgr-r >^>!r:: SoundPlay, *64 Reload return ;---------------------------------- ; Modifications for Guild Wars 2 #IfWinActive ahk_group prog ; CTRL-ALT-G: Trading post listing mode ^!g::Send I am Evon Gnashblade ; left Windows key is F5 LWin::F5 ;LWin::return ; CTRL-ALT-M: toggle mouse capture ^!M:: SoundPlay, *64 CHECK_MOUSE_POS := not CHECK_MOUSE_POS return ; convert coordinates relative to the client area of given window to screen coordinates ClientToScreen(hwnd, ByRef x, ByRef y) { local pt VarSetCapacity(pt, 8) NumPut(x, pt, 0, "int") NumPut(y, pt, 4, "int") DllCall("ClientToScreen", "Ptr", hwnd, "Ptr", &pt) x := NumGet(pt, 0, "int") y := NumGet(pt, 4, "int") } ; get width and height of the client area of given window GetClientRect(hwnd, ByRef w, ByRef h) { local rc VarSetCapacity(rc, 16) DllCall("GetClientRect", "Ptr", hwnd, "Ptr", &rc) w := NumGet(rc, 8, "int") h := NumGet(rc, 12, "int") } ; Track mouse by monitoring WM_MOUSEMOVE messages. If the mouse is about to leave the area defined ; by prog_xpos, prog_maxx, prog_ypos, prog_maxy, suppress the message, so the mouse isn't actually ; able to leave. MouseProc(nCode, wParam, lParam) { local x, y critical if (wParam = 0x200) { ; WM_MOUSEMOVE x := NumGet(lParam+0, 0, "int") y := NumGet(lParam+4, 0, "int") if (x < prog_xpos or x >= prog_maxx or y < prog_ypos or y >= prog_maxy) { if (DoMouseCheck) { if (GetKeyState(CHECK_MOUSE_SKIP, "P")) { DoMouseCheck := false } else { return 1 } } } else { DoMouseCheck := true } } return DllCall("CallNextHookEx", "Ptr", MouseHook , "int", nCode, "uint", wParam, "uint", lParam) }