Advertisement
Lorenzo501

Guild Wars 2 Macro Tests (redundant)

Aug 6th, 2024 (edited)
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 128.10 KB | None | 0 0
  1. MODIFIED AT: 10/11/22 >> gw4/gw4.ahk:
  2.  
  3. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  4. ; #Warn ; Enable warnings to assist with detecting common errors.
  5. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  6. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  7. ; Any attempt to launch this script when it's already running will reload it (the dialog box that normally appears in this situation gets skipped)
  8. #SingleInstance Force
  9. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  10. #InstallMouseHook
  11. ; Runs the game and terminates the macro when the game window doesn't exist any longer and wasn't being restarted either (keep this at the bottom of the auto-execute section)
  12. RunWait, "C:\Program Files\Guild Wars 2\Gw2-64.exe"
  13. ManageApp()
  14. ; The code below only executes for the Guild Wars 2 window
  15. #Include, <functions>
  16. #Include, <hotkeys>
  17.  
  18.  
  19. *********************************************************************************************************************************************************************************************
  20. MODIFIED AT: 10/11/22 >> gw4/lib/functions.ahk:
  21.  
  22. ; Terminates the macro if the game doesn't restart itself within 30 seconds. And also has recursive code, which restarts this method each time the game crashes and immediately restarts
  23. ManageApp()
  24. {
  25. WinWait, Guild Wars 2,, 30
  26.  
  27. if (ErrorLevel == 1)
  28. ExitApp
  29. else
  30. {
  31. WinWaitClose
  32. ManageApp()
  33. }
  34. }
  35. ToggleChatState()
  36. {
  37. Hotkey, If, (WinActive("Guild Wars 2"))
  38. HotKey, v, Toggle
  39. global isChatActive := !isChatActive
  40. }
  41. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  42. WiggleCamera()
  43. {
  44. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  45. SetMouseDelay, 1
  46.  
  47. Send, {Click -15 0 0 Relative}
  48. Send, {Click 15 0 0 Relative}
  49. }
  50. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  51. LButtonAboutFace(functionKey)
  52. {
  53. shouldUsePostponableHotkeys := true
  54. Critical
  55. MouseGetPos, initialCursorX, initialCursorY
  56. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  57.  
  58. if (GetKeyState("LButton") and GetKeyState("RButton"))
  59. Send, {%functionKey%}
  60. else if (GetKeyState("LButton"))
  61. {
  62. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  63. Send, {LButton up}
  64. Sleep, 40
  65. Send, {LButton down}
  66.  
  67. WiggleCamera()
  68. Send, {%functionKey%}
  69. }
  70. else if (GetKeyState("RButton"))
  71. {
  72. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  73. Send, {RButton up}
  74. Send, {RButton down}
  75.  
  76. WiggleCamera()
  77.  
  78. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  79. Send, {RButton up}
  80.  
  81. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  82. Click, %windowWidth% %windowY% Down
  83. Send, {%functionKey%}
  84. Click, Up
  85. Send, {Click %initialCursorX% %initialCursorY% 0}
  86.  
  87. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  88. if (GetKeyState("RButton", "P"))
  89. {
  90. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  91. Sleep, 525
  92.  
  93. if (GetKeyState("RButton", "P"))
  94. Send, {RButton down}
  95. }
  96. }
  97. else
  98. {
  99. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  100. Click, %windowWidth% %windowY% Down
  101. WiggleCamera()
  102. Send, {%functionKey%}
  103. Click, Up
  104. Send, {Click %initialCursorX% %initialCursorY% 0}
  105. }
  106.  
  107. shouldUsePostponableHotkeys := false
  108. }
  109. ; Left-click outside the chat area with an active chat input field and left-click inside an inactive chat input field both toggles the chat state of the macro as well
  110. OnLButton()
  111. {
  112. MouseGetPos, currentCursorX, currentCursorY
  113.  
  114. if (isChatActive)
  115. {
  116. if (currentCursorX > 490 or currentCursorY < 1147)
  117. ToggleChatState()
  118. }
  119. else if (currentCursorX < 482 and currentCursorY > 1370)
  120. ToggleChatState()
  121. }
  122.  
  123.  
  124. *********************************************************************************************************************************************************************************************
  125. MODIFIED AT: 10/11/22 >> gw4/lib/hotkeys.ahk:
  126.  
  127. #If (WinActive("Guild Wars 2"))
  128. ; Prevents hotkey interference when the chat is being used
  129. ~Enter::ToggleChatState()
  130. ; Dodge Jump
  131. ~v::Send, {Space}
  132. F3::
  133. F4::LButtonAboutFace("F3")
  134. ; This fixes the bug where the character suddenly rotates in a random manner when the player goes on their mount while auto-run is active and the right mouse button is being pressed
  135. ~'::
  136. ; Toggled boolean variable that becomes true when mounting up
  137. isMountUpAction := !isMountUpAction
  138. ; This is for when the player actually mounts up and is physically pressing the right mouse button but not the left mouse button (aka the situation where the bug happens)
  139. if (isMountUpAction and GetKeyState("RButton", "P") and !GetKeyState("LButton", "P"))
  140. {
  141. shouldUsePostponableHotkeys := true
  142. Critical
  143.  
  144. ; The best cursor placement to have when the mouse buttons are no longer pressed and the center of the screen also guarantees the code to work
  145. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  146. halfWindowWidth := windowWidth / 2
  147. halfWindowHeight := windowHeight / 2
  148.  
  149. ; This is also necessary to make the original bugfix work and a high sleep time helps the user with regaining camera control automatically
  150. Send, {RButton up}
  151. Sleep, 100
  152.  
  153. ; Press both mouse buttons (prevents auto-run from being stopped accidentally later on and this also makes wiggling the camera possible)
  154. Send, {Click %halfWindowWidth% %halfWindowHeight% Down}{RButton down}
  155.  
  156. ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user and holding both mouse buttons for atleast 50 milliseconds longer
  157. WiggleCamera()
  158. Sleep, 50
  159.  
  160. ; Executes code for physical mouse button state combinations (when both mouse buttons are physically pressed then it'll simply return without releasing them)
  161. if (!GetKeyState("LButton", "P") and GetKeyState("RButton", "P"))
  162. {
  163. ; Release left mouse button and use auto-run instead
  164. Send, {LButton up}
  165. Send, {r}
  166. }
  167. else if (!GetKeyState("LButton", "P") and !GetKeyState("RButton", "P"))
  168. ; Releases both mouse buttons
  169. Send, {LButton up}{RButton up}
  170.  
  171. shouldUsePostponableHotkeys := false
  172. }
  173. return
  174. ; The hotkeys below can be made postponable but aren't by default so that they work faster whenever possible (set the shouldUsePostponableHotkeys boolean to false when you're done using it)
  175. #If (WinActive("Guild Wars 2") and !shouldUsePostponableHotkeys)
  176. ~LButton::OnLButton()
  177. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  178. ; The hotkeys below can be made postponable by setting the shouldUsePostponableHotkeys boolean to true
  179. #If (WinActive("Guild Wars 2") and shouldUsePostponableHotkeys)
  180. 4::Send, {4}
  181. LButton::
  182. Send, {LButton}
  183. OnLButton()
  184. return
  185.  
  186. RButton::Send, {RButton}
  187. w::Send, {w}
  188. a::Send, {a}
  189. s::Send, {s}
  190. d::Send, {d}
  191.  
  192.  
  193. *********************************************************************************************************************************************************************************************
  194. MODIFIED AT: 7/10/24 >> [DONE]GW2 BUG TEST RESULTS AND NEW PROPOSED FIX.txt:
  195.  
  196. I held left-button pressed, auto-run enabled (no AHK script running ofc)
  197. and then pressed mount-key, screen-face direction stayed the same but mount ran to the right [no mousemove blocking necessary either! and no need for postponing via mousehook!]
  198. it would be better if "LMB down, LMB up, RMB down & RMB up" get postponed instead of blocked
  199. don't need mousehook for blocking e.g. if the user had something pressed beforehand and released while blocking, it'd get stuck
  200. /
  201. // IF THIS LOOKS UGLY THEN I CAN TRY TO TEMPORARILY HIDE THE CURSOR WHEN IT GETS MOVED PROGRAMMATICALLY (but first try w/ SendInput + "A_KeyDelay := -1" in case it reverts to SendEvent)
  202. mouse in gw2 is only used for manual-run, activating chat and clicking some icons, it does not matter when it's slightly slower than usual due to a LButton hotkey (nor due to a mousehook)
  203. so on LButton hotkey it can check if the mount-up icon is clicked > block LMB down, LMB up, RMB down & RMB up > send CURSOR move w/ pos argument being a bit to the right of the icon
  204. > send RMB down > send mount-up key > sleep > send RMB up > send CURSOR move w/ pos argument being where it originally was (on icon) > unblock the mouse buttons
  205. | >>> [unmounts automatically when in water, death, logged-out.. DETECT THE MOUNT-DOWN ICON PIXEL!!!]
  206. USE `#HotIf (WinActive(gw2))` TO REMEMBER WHEN THE CHAT IS MADE ACTIVE/INACTIVE //AND TO REMEMBER IF THE CHARACTER IS MOUNTED-UP, WHEN MOUNTED-UP THEN NATIVELY MOUNT-DOWN IN LMB & ' HOTKEY
  207.  
  208. THE CHAT CAN USE THE MOUNT-UP KEY (') WHICH OFC JUST NEEDS TO BE TEXT, SO I ALSO NEED TO CHECK IF THE CHAT HAS BEEN MADE ACTIVE/INACTIVE VIA CLICK OR ENTER, OR MADE INACTIVE VIA ESCAPE
  209.  
  210.  
  211. ON MOUNT-UP KEY:
  212. don't need mousehook for blocking this will continue auto-run in the screen-faced direction (there is no way to use the character-faced direction)
  213. if only LMB is active / /
  214. then assume auto-run is on > block LMB down, LMB up, RMB down & RMB up > send LMB up > send RMB down > send mount-up key > sleep > send RMB up > send LMB down > unblock the mouse buttons
  215. /
  216. otherwise it will stop auto-run (if it was enabled). can't send LMB + RMB, and then auto-run w/o knowing that it was on
  217.  
  218. don't need mousehook for blocking
  219. else if LMB nor RMB is active /
  220. block LMB down, LMB up, RMB down & RMB up > send CURSOR move w/ pos argument being x: A_ScreenWidth, y: 0 ̶A̶_̶S̶c̶r̶e̶e̶n̶H̶e̶i̶g̶h̶t̶ ̶/̶ ̶2 (seems like a safe zone w/o windows) > send RMB down
  221. > send mount-up key > sleep > send RMB up > send CURSOR move w/ pos argument being where it originally was > unblock the mouse buttons
  222.  
  223.  
  224.  
  225.  
  226. ELSE (if RMB is active, or in other words: if only RMB is active or both LMB and RMB is active)
  227. just send mount-up key (in theory it should be fine, this seems like all it rly needs)
  228.  
  229.  
  230.  
  231.  
  232. [I DON'T THINK THIS HAS THE ISSUE, ESPECIALLY WHEN THE 'ONLY-LMB-ACTIVE' SOLUTION WORKS, B/C IT USES RMB....]
  233. if only RMB is active (not sure if this has the issue but if it does, then use the following solution)
  234. then assume auto-run is on >
  235. [I DON'T THINK THIS HAS THE ISSUE, ESPECIALLY WHEN THE 'ONLY-LMB-ACTIVE' SOLUTION WORKS, B/C IT USES RMB....]
  236. if both LMB & RMB are active (not sure if this has the issue but if it does, then use the following solution)
  237. know that manual-run is on >
  238.  
  239.  
  240. *********************************************************************************************************************************************************************************************
  241. MODIFIED AT: 7/12/24 >> _______________AHKv2 Guild Wars 2 Auto-Fly (MOVED INTO MAIN FILE BUT NOT THE COMMENT AT THE TOP).ahk:
  242.  
  243. ;NOTE: since the fly process will take a long time, the temporary key duration will stay on 500ms for a long time.. so I might need to temporarily change it back to -1 in other functions!
  244.  
  245. #Requires AutoHotkey 2.0
  246. A_KeyDelay := -1 ; For Send b/c it reverts to the Event SendMode when another AHK script installs a native low-level keyboard/mouse hook
  247.  
  248. /* TODO:
  249. pause depleted-fly-energy mode when chat gets opened
  250. resume either sufficient-fly-energy mode or depleted-fly-energy mode when chat gets closed
  251. pause sufficient-fly-energy mode when "s" gets pressed and chat isn't open and then execute Send("s down") instead
  252. resume sufficient-fly-energy mode when "w" gets pressed and chat isn't open
  253. pause depleted-fly-energy mode when "s" gets pressed
  254. resume depleted-fly-energy mode when "w" gets pressed
  255. when auto-fly stops, then release whichever key remained pressed if sufficient-fly-energy mode was active, if "w" remained pressed then it should auto-run instead
  256. */
  257. ; Auto-Fly (required resolution: Full Screen - 2560 x 1440)
  258. ~Space::
  259. {
  260. Sleep(500)
  261.  
  262. if (DetermineFlyStatus())
  263. {
  264. keyDurationPrevious := SetKeyDelay(, 500)
  265. isFlyEnergyDepleted := false
  266. Send("{w down}")
  267.  
  268. loop
  269. {
  270. if (DetermineFlyStatus())
  271. {
  272. if (isFlyEnergyDepleted)
  273. SendEvent("w")
  274. else if (PixelGetColor(1270, 1230) = 0x181B18)
  275. isFlyEnergyDepleted := true
  276. else
  277. Sleep(50)
  278. }
  279. else
  280. break
  281.  
  282. }
  283.  
  284. A_KeyDuration := keyDurationPrevious
  285. }
  286.  
  287. DetermineFlyStatus() => PixelGetColor(1111, 1230) = 0x764E1B && PixelGetColor(1455, 1230) = 0xAA6404
  288. }
  289.  
  290.  
  291. *********************************************************************************************************************************************************************************************
  292. MODIFIED AT: 4/21/24 >> AHKv2 Guild Wars 2 - backup containing some old code.ahk:
  293.  
  294. #Requires AutoHotkey 2.0
  295.  
  296. F12::Reload() ;FOR TESTING
  297.  
  298. ; Any attempt to launch this script when it's already running will reload it (the dialog box that normally appears in this situation gets skipped)
  299. #SingleInstance Force
  300.  
  301. A_KeyDelay := -1 ; For Send b/c it reverts to the Event SendMode when another AHK script installs a low-level keyboard hook
  302. A_MouseDelay := -1 ; For sending a left- or right-click with Send b/c it reverts to the Event SendMode when another AHK script installs a low-level keyboard hook
  303. AutoRun := {IsActive: false} ; Ad hoc object, usable w/ dot notation (no need for class)
  304. HotIfWinActive("ahk_exe Gw2-64.exe")
  305. ;Run("C:\Program Files\Guild Wars 2\Gw2-64.exe")
  306. EVENT_OBJECT_CREATE := 0x8000
  307. ;DllCall("SetWinEventHook", "UInt", EVENT_OBJECT_CREATE, "UInt", EVENT_OBJECT_CREATE, "Ptr", 0, "Ptr", CallbackCreate(HandleGuildWars2Event), "UInt", 0, "UInt", 0, "UInt", 0)
  308. ;ManageApp() ; Terminates the macro when the game window doesn't exist any longer and wasn't being restarted either (keep this at the bottom of the auto-execute section)
  309.  
  310. #HotIf (WinActive("ahk_exe Gw2-64.exe"))
  311.  
  312. ; To hide the OSD
  313. Volume_Up::SoundSetVolume("+2")
  314. Volume_Down::SoundSetVolume("-2")
  315.  
  316. ~w::
  317. ~s::AutoRun.IsActive := false
  318. ~r::AutoRun.IsActive := !AutoRun.IsActive
  319.  
  320. $F3::
  321. F4::LButtonAboutFace("F3") ; Keep LButton pressed (not RButton) when using About Face if you need to keep the enemy targeted (otherwise you'll lose the target, but can't be automated)
  322.  
  323. $'::return ; Mount-up hotkey
  324.  
  325. LButton:: ; Necessary when making a `LButton up` hotkey (but I was gonna use this for chat and mount-up click detection anyway)
  326. {
  327. Send("{LButton down}")
  328.  
  329. if (GetKeyState("RButton"))
  330. AutoRun.IsActive := false
  331. }
  332.  
  333. ; Serves mainly as a postponeable hotkeys
  334. LButton up::Send("{LButton up}") ; Necessary when making a `LButton` hotkey (but I needed this to be postponeable anyway)
  335. RButton::
  336. {
  337. Send("{RButton down}")
  338.  
  339. if (GetKeyState("LButton"))
  340. AutoRun.IsActive := false
  341. }
  342. RButton up::Send("{RButton up}")
  343.  
  344. ;********** LIBRARY **********
  345.  
  346. ; This will remove the HDR flickering issue when the gw2 launcher creates a fullscreen wnd
  347. HandleGuildWars2Event(hWinEventHook, event, hWnd, *)
  348. {
  349. try
  350. if (WinGetClass(hWnd) = "ArenaNet_Gr_Window_Class")
  351. {
  352. WinSetTransparent(0, hWnd)
  353. Sleep(2000)
  354. WinSetTransparent("Off", hWnd)
  355. }
  356. }
  357.  
  358. ; Terminates the macro if the game doesn't restart itself within 30 seconds. And also has recursive code, which restarts this method each time the game crashes and immediately restarts
  359. ManageApp()
  360. {
  361. if (WinWait("ahk_exe Gw2-64.exe",, 30))
  362. {
  363. WinWaitClose()
  364. ManageApp()
  365. }
  366. else
  367. ExitApp()
  368. }
  369.  
  370. ; [EVEN BETTER SOLUTION TO MAKE AboutFace ROTATE RELIABLY; by programmatically holding LButton and "w" pressed while fnKey is send]
  371. ; [actually, I think you can even fix the issue where AboutFace doesn't rotate; by programmatically holding RButton pressed while it does the camera wiggle. Before the fnKey is send ofc]
  372. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  373. LButtonAboutFace(fnKey)
  374. {
  375. Hotkey("$4", (*) => Send("4"), "On") ; Makes it postponeable
  376. Critical()
  377.  
  378. if (!GetKeyState("LButton") && GetKeyState("RButton")) ; With RButton down, that means the cursor is already in a safe spot
  379. {
  380. ; This prevents About Face from doing nothing
  381. if (!AutoRun.IsActive)
  382. Send("r")
  383.  
  384. ; Holds the LButton pressed down while it sends the fn key (the following keeps auto-run: {LButton down} + {RButton down} = manual run + camera rotating along with the character)
  385. Send("{RButton up}{LButton down}{" fnKey "}{LButton up}") ; is prevented
  386.  
  387. if (!AutoRun.IsActive)
  388. Sleep(40), Send("r")
  389.  
  390. ; Delay logically pressing RButton down again to prevent the camera from turning 180 degrees
  391. Sleep(525)
  392.  
  393. A_CoordModeMouse := "Screen"
  394. MouseGetPos(&startCursorX, &startCursorY)
  395.  
  396. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  397. while (GetKeyState("RButton", "P"))
  398. {
  399. static cursorMoveThreshold := 10
  400. MouseGetPos(&cursorX, &cursorY)
  401.  
  402. if
  403. (
  404. cursorX < startCursorX - cursorMoveThreshold ||
  405. cursorX > startCursorX + cursorMoveThreshold ||
  406. cursorY < startCursorY - cursorMoveThreshold ||
  407. cursorY > startCursorY + cursorMoveThreshold
  408. )
  409. {
  410. Send("{RButton down}")
  411.  
  412. break
  413. }
  414.  
  415. Sleep(10)
  416. }
  417.  
  418. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  419. ;if (GetKeyState("RButton", "P"))
  420. ;Send("{RButton down}")
  421.  
  422. }
  423. else if (!GetKeyState("LButton")) ; No mouse buttons are being pressed down, that means the cursor might be in an unsafe spot! So watch out for that when using the About Face fn key
  424. {
  425. ; This prevents About Face from doing nothing
  426. if (!AutoRun.IsActive)
  427. Send("r")
  428.  
  429. ; Makes it postponeable
  430. ;Hotkey("$RButton", (*) => Send("{RButton down}"), "On")
  431. ;Hotkey("$RButton up", (*) => Send("{RButton up}"), "On")
  432.  
  433. ; Holds the LButton pressed down (whether it's in a safe spot or not, moving the cursor programmatically looks bad so I'm skipping that) while it sends the fn key
  434. Send("{LButton down}{" fnKey "}{LButton up}")
  435.  
  436. if (!AutoRun.IsActive)
  437. Sleep(40), Send("r")
  438.  
  439. ; Postpone any RButton down presses that might occur, to prevent the camera from turning 180 degrees
  440. Sleep(525)
  441. ;SetTimer((*) => (Hotkey("$RButton", "Off"), Hotkey("$RButton up", "Off")), -1)
  442. }
  443. else
  444. {
  445. ; This prevents About Face from doing nothing
  446. if (!AutoRun.IsActive)
  447. Send("r")
  448.  
  449. Send("{" fnKey "}")
  450.  
  451. if (!AutoRun.IsActive)
  452. Sleep(40), Send("r")
  453. }
  454.  
  455. SetTimer((*) => Hotkey("$4", "Off"), -1) ; Makes it use the faster native fn instead of being postponeable (after any postponed ones have been sent)
  456. }
  457.  
  458.  
  459. *********************************************************************************************************************************************************************************************
  460. MODIFIED AT: 5/28/24 >> AHKv2 Guild Wars 2 - backup from right before I added the mount-up and auto-fly feature.ahk:
  461.  
  462. #Requires AutoHotkey 2.0
  463.  
  464. F12::Reload() ;FOR TESTING (MIGHT ALSO HAVE COMMENTED-OUT THE `Run` & `ManageApp` BELOW, UNCOMMENT THEM WHEN EVERYTHING WORKS)
  465.  
  466. ; Any attempt to launch this script when it's already running will reload it (the dialog box that normally appears in this situation gets skipped)
  467. #SingleInstance Force
  468.  
  469. ; To make it work when the active gw2 window is elevated
  470. if (!InStr(A_AhkPath, "_UIA.exe"))
  471. {
  472. Run("*UIAccess " A_ScriptFullPath)
  473. ExitApp()
  474. }
  475.  
  476. A_HotkeyInterval := 0 ; To disable the warning dialog (can otherwise appear when a hotkey was being pressed down for too long while being postponed)
  477. A_CoordModeMouse := "Screen"
  478. A_KeyDelay := -1, A_KeyDuration := -1, A_MouseDelay := -1 ; For Send b/c it reverts to the Event SendMode when another AHK script installs a native low-level keyboard/mouse hook
  479. autoRun := {IsActive: false} ; Ad hoc object, usable w/ dot notation (no need for class)
  480. HotIfWinActive("ahk_exe Gw2-64.exe") ; For hotkeys that are created at runtime
  481.  
  482. ; To remove blue flickering at startup, the gw2 exe properties are set to both compatibility mode "Windows Vista (Service Pack 2)" and settings "Run this program as an administrator".
  483. ; This cmd runs an admin task that's added to Task Scheduler w/ start program action "%ProgramFiles%\Guild Wars 2\Gw2-64.exe", so there won't be an elevation prompt every time you start gw2
  484. Run("schtasks /run /tn `"Guild Wars 2`"",, "Hide")
  485.  
  486. ManageApp() ; Terminates the macro when the game window doesn't exist any longer and wasn't being restarted either (keep this at the bottom of the auto-execute section)
  487.  
  488. #HotIf (WinActive("ahk_exe Gw2-64.exe"))
  489.  
  490. ; To hide the OSD
  491. Volume_Up::SoundSetVolume("+2")
  492. Volume_Down::SoundSetVolume("-2")
  493.  
  494. ~w::
  495. ~s::autoRun.IsActive := false
  496. ~r::autoRun.IsActive := !autoRun.IsActive
  497.  
  498. $F3::
  499. F4::LButtonAboutFace("F3") ; Keep LButton pressed (not RButton) when using About Face if you need to keep the enemy targeted (otherwise you'll lose the target, but rly can't be automated)
  500. ; ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
  501. $'::return ; Mount-up hotkey
  502.  
  503. LButton:: ; TODO: add chat and mount-up click detection
  504. {
  505. Send("{LButton down}")
  506.  
  507. if (GetKeyState("RButton"))
  508. autoRun.IsActive := false
  509. }
  510.  
  511. ; These serve mainly as postponeable hotkeys (and apparently you cannot make a btn-down hotkey w/o making a btn-up hotkey, and vice versa)
  512. LButton up::Send("{LButton up}")
  513. RButton::
  514. {
  515. Send("{RButton down}")
  516.  
  517. if (GetKeyState("LButton"))
  518. autoRun.IsActive := false
  519. }
  520. RButton up::Send("{RButton up}")
  521.  
  522. ;********** LIBRARY **********
  523.  
  524. /*
  525. If compatibility mode + admin doesn't reliably remove blue flickering at startup, then use this instead:
  526. EVENT_OBJECT_CREATE := 0x8000
  527. DllCall("SetWinEventHook", "UInt", EVENT_OBJECT_CREATE, "UInt", EVENT_OBJECT_CREATE, "Ptr", 0, "Ptr", CallbackCreate(HandleGuildWars2Event), "UInt", 0, "UInt", 0, "UInt", 0)
  528. */
  529.  
  530. ; This will remove the blue flickering issue when the gw2 launcher creates a fullscreen wnd
  531. HandleGuildWars2Event(hWinEventHook, event, hWnd, *)
  532. {
  533. try
  534. if (WinGetClass(hWnd) = "ArenaNet_Gr_Window_Class")
  535. {
  536. WinSetTransparent(0, hWnd)
  537. Sleep(2050)
  538. WinSetTransparent("Off", hWnd)
  539. }
  540. }
  541.  
  542. ; Terminates the macro if the game doesn't restart itself within 30 seconds. And also has recursive code, which restarts this method each time the game crashes and immediately restarts
  543. ManageApp()
  544. {
  545. if (WinWait("ahk_exe Gw2-64.exe",, 30))
  546. {
  547. WinWaitClose()
  548. ManageApp()
  549. }
  550. else
  551. ExitApp()
  552. }
  553.  
  554. ; Uses the About Face feature without unintentionally turning the camera along with it (requires the keybind that's used in guild wars 2)
  555. LButtonAboutFace(fnKey)
  556. {
  557. static cursorMoveThreshold := 5
  558. Hotkey("$4", (*) => Send("4"), "On") ; Makes it postponeable
  559. Critical()
  560.  
  561. if (!GetKeyState("LButton") && GetKeyState("RButton")) ; With RButton down, that means the cursor is already in a safe spot
  562. {
  563. BlockInput("MouseMove")
  564. Send("{RButton up}")
  565.  
  566. ; This prevents About Face from doing nothing
  567. if (!autoRun.IsActive)
  568. Send("r")
  569.  
  570. ; Holds the LButton pressed down while it sends the fn key (the following stops auto-run: {LButton down} + {RButton down} = manual run + camera rotating along with the character)
  571. Send("{LButton down}{" fnKey "}{LButton up}")
  572.  
  573. if (!autoRun.IsActive)
  574. Sleep(40), Send("r")
  575.  
  576. ; Delay logically pressing RButton down again to prevent the camera from turning 180 degrees
  577. Sleep(525)
  578.  
  579. BlockInput("MouseMoveOff")
  580. MouseGetPos(&startCursorX, &startCursorY)
  581. Critical("Off")
  582. Sleep(-1)
  583. SetTimer((*) => Hotkey("$4", "Off"), -1) ; Makes it use the faster native fn instead of being postponeable (after any postponed ones have been sent)
  584. Sleep(1)
  585.  
  586. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  587. while (GetKeyState("RButton", "P"))
  588. {
  589. MouseGetPos(&cursorX, &cursorY)
  590.  
  591. if
  592. (
  593. GetKeyState("LButton", "P") ||
  594. cursorX < startCursorX - cursorMoveThreshold ||
  595. cursorX > startCursorX + cursorMoveThreshold ||
  596. cursorY < startCursorY - cursorMoveThreshold ||
  597. cursorY > startCursorY + cursorMoveThreshold
  598. )
  599. {
  600. Send("{RButton down}")
  601.  
  602. return
  603. }
  604.  
  605. Sleep(0)
  606. }
  607. }
  608. else if (!GetKeyState("LButton")) ; No mouse buttons are being pressed down, that means the cursor might be in an unsafe spot! So watch out for that when using the About Face fn key
  609. {
  610. ; This prevents About Face from doing nothing
  611. if (!autoRun.IsActive)
  612. Send("r")
  613.  
  614. ; Holds the LButton pressed down (whether it's in a safe spot or not, moving the cursor programmatically looks bad so I'm skipping that) while it sends the fn key
  615. Send("{LButton down}{" fnKey "}{LButton up}")
  616.  
  617. ; Postpone any RButton down presses that might occur, to prevent the camera from turning 180 degrees, and stop auto-run again if it was activated above
  618. if (autoRun.IsActive)
  619. Sleep(525)
  620. else
  621. Sleep(40), Send("r"), Sleep(485)
  622. }
  623. else if (!GetKeyState("RButton") && !autoRun.IsActive) ; This prevents About Face from doing nothing when merely LButton is pressed
  624. Send("r{" fnKey "}"), Sleep(40), Send("r")
  625. else ; When both LButton and RButton are being pressed down then there are no issues (it will intentionally rotate both the character and the camera)
  626. Send("{" fnKey "}")
  627.  
  628. SetTimer((*) => Hotkey("$4", "Off"), -1) ; Makes it use the faster native fn instead of being postponeable (after any postponed ones have been sent)
  629. }
  630.  
  631.  
  632. *********************************************************************************************************************************************************************************************
  633. MODIFIED AT: 4/21/24 >> AHKv2 Guild Wars 2 - backup of minimumRepressDelay that somehow doesn't work in this code structure.ahk:
  634.  
  635. #Requires AutoHotkey 2.0
  636.  
  637. F12::Reload() ;FOR TESTING
  638.  
  639. ; Any attempt to launch this script when it's already running will reload it (the dialog box that normally appears in this situation gets skipped)
  640. #SingleInstance Force
  641.  
  642. A_HotkeyInterval := 0 ; To disable the warning dialog (can otherwise appear when a hotkey was being pressed down for too long while being postponed)
  643. A_CoordModeMouse := "Screen"
  644. A_KeyDelay := -1 ; For Send b/c it reverts to the Event SendMode when another AHK script installs a low-level keyboard hook
  645. A_MouseDelay := -1 ; For sending a left- or right-click with Send b/c it reverts to the Event SendMode when another AHK script installs a low-level keyboard hook
  646. autoRun := {IsActive: false} ; Ad hoc object, usable w/ dot notation (no need for class)
  647. aboutFace := {IsActive: false} ; Ad hoc object, usable w/ dot notation (no need for class)
  648. HotIfWinActive("ahk_exe Gw2-64.exe") ; For hotkeys that are created at runtime
  649. ;Run("C:\Program Files\Guild Wars 2\Gw2-64.exe")
  650. EVENT_OBJECT_CREATE := 0x8000
  651. ;DllCall("SetWinEventHook", "UInt", EVENT_OBJECT_CREATE, "UInt", EVENT_OBJECT_CREATE, "Ptr", 0, "Ptr", CallbackCreate(HandleGuildWars2Event), "UInt", 0, "UInt", 0, "UInt", 0)
  652. ;ManageApp() ; Terminates the macro when the game window doesn't exist any longer and wasn't being restarted either (keep this at the bottom of the auto-execute section)
  653.  
  654. #HotIf (WinActive("ahk_exe Gw2-64.exe"))
  655.  
  656. ; To hide the OSD
  657. Volume_Up::SoundSetVolume("+2")
  658. Volume_Down::SoundSetVolume("-2")
  659.  
  660. ~w::
  661. ~s::autoRun.IsActive := false
  662. ~r::autoRun.IsActive := !autoRun.IsActive
  663.  
  664. $F3::
  665. F4::LButtonAboutFace("F3") ; Keep LButton pressed (not RButton) when using About Face if you need to keep the enemy targeted (otherwise you'll lose the target, but rly can't be automated)
  666. ; ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑
  667. $'::return ; Mount-up hotkey
  668.  
  669. LButton:: ; Necessary when making a `LButton up` hotkey (but I was gonna use this for chat and mount-up click detection anyway)
  670. {
  671. Send("{LButton down}")
  672.  
  673. if (GetKeyState("RButton"))
  674. autoRun.IsActive := false
  675. }
  676.  
  677. ; These serve mainly as a postponeable hotkeys
  678. LButton up::Send("{LButton up}") ; Necessary when making a `LButton` hotkey (but I needed this to be postponeable anyway)
  679. RButton::
  680. {
  681. Send("{RButton down}")
  682.  
  683. if (GetKeyState("LButton"))
  684. autoRun.IsActive := false
  685. }
  686. RButton up::Send("{RButton up}")
  687.  
  688. ;********** LIBRARY **********
  689.  
  690. ; This will remove the HDR flickering issue when the gw2 launcher creates a fullscreen wnd
  691. HandleGuildWars2Event(hWinEventHook, event, hWnd, *)
  692. {
  693. try
  694. if (WinGetClass(hWnd) = "ArenaNet_Gr_Window_Class")
  695. {
  696. WinSetTransparent(0, hWnd)
  697. Sleep(2050)
  698. WinSetTransparent("Off", hWnd)
  699. }
  700. }
  701.  
  702. ; Terminates the macro if the game doesn't restart itself within 30 seconds. And also has recursive code, which restarts this method each time the game crashes and immediately restarts
  703. ManageApp()
  704. {
  705. if (WinWait("ahk_exe Gw2-64.exe",, 30))
  706. {
  707. WinWaitClose()
  708. ManageApp()
  709. }
  710. else
  711. ExitApp()
  712. }
  713.  
  714. ; Uses the About Face feature without unintentionally turning the camera along with it (requires the keybind that's used in guild wars 2)
  715. LButtonAboutFace(fnKey)
  716. {
  717. static cursorMoveThreshold := 5, minimumRepressDelay := 700 ;525
  718.  
  719. if (aboutFace.IsActive)
  720. return
  721. else
  722. aboutFace.IsActive := true
  723.  
  724. Hotkey("$4", (*) => Send("4"), "On") ; Makes it postponeable
  725. Critical()
  726.  
  727. if (!GetKeyState("LButton") && GetKeyState("RButton")) ; With RButton down, that means the cursor is already in a safe spot
  728. {
  729. Send("{RButton up}")
  730.  
  731. ; This prevents About Face from doing nothing
  732. if (!autoRun.IsActive)
  733. Send("r")
  734.  
  735. ; Holds the LButton pressed down while it sends the fn key (the following stops auto-run: {LButton down} + {RButton down} = manual run + camera rotating along with the character)
  736. Send("{LButton down}{" fnKey "}{LButton up}")
  737.  
  738. if (!autoRun.IsActive)
  739. Sleep(40), Send("r")
  740.  
  741. ; Delay logically pressing RButton down again to prevent the camera from turning 180 degrees
  742. ;Sleep(525)
  743.  
  744. startTime := A_TickCount
  745. MouseGetPos(&startCursorX, &startCursorY)
  746. Critical("Off")
  747. Sleep(-1)
  748. SetTimer((*) => Hotkey("$4", "Off"), -1) ; Makes it use the faster native fn instead of being postponeable (after any postponed ones have been sent)
  749. Sleep(1)
  750.  
  751. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  752. while (GetKeyState("RButton", "P"))
  753. {
  754. MouseGetPos(&cursorX, &cursorY)
  755.  
  756. if
  757. (
  758. GetKeyState("LButton", "P") ||
  759. cursorX < startCursorX - cursorMoveThreshold ||
  760. cursorX > startCursorX + cursorMoveThreshold ||
  761. cursorY < startCursorY - cursorMoveThreshold ||
  762. cursorY > startCursorY + cursorMoveThreshold
  763. )
  764. {
  765. ; Delay logically pressing RButton down again to prevent the camera from turning 180 degrees
  766. if (!GetKeyState("LButton", "P") && (repressDelay := A_TickCount - startTime) < minimumRepressDelay)
  767. Sleep(repressDelay) ;, send("{enter}{sleep 500}A) " repressDelay)
  768. ;else
  769. ;send("{enter}{sleep 500}B) " repressDelay)
  770. ;return
  771. ;send("r{LButton down}") ; auto-run could've been off already at this point
  772. ;sleep(20)
  773. ;send("{LButton up}")
  774. ;sleep(20)
  775. Send("{RButton down}")
  776. ;sleep(20)
  777. ;send("r")
  778. aboutFace.IsActive := false
  779. return
  780. }
  781.  
  782. Sleep(0)
  783. }
  784. }
  785. else if (!GetKeyState("LButton")) ; No mouse buttons are being pressed down, that means the cursor might be in an unsafe spot! So watch out for that when using the About Face fn key
  786. {
  787. ; This prevents About Face from doing nothing
  788. if (!autoRun.IsActive)
  789. Send("r")
  790.  
  791. ; Holds the LButton pressed down (whether it's in a safe spot or not, moving the cursor programmatically looks bad so I'm skipping that) while it sends the fn key
  792. Send("{LButton down}{" fnKey "}{LButton up}")
  793.  
  794. if (!autoRun.IsActive)
  795. Sleep(40), Send("r")
  796.  
  797. ; Postpone any RButton down presses that might occur, to prevent the camera from turning 180 degrees
  798. Sleep(autoRun.IsActive ? minimumRepressDelay : minimumRepressDelay - 40)
  799. }
  800. else if (!GetKeyState("RButton") && !autoRun.IsActive) ; This prevents About Face from doing nothing when merely LButton is pressed
  801. Send("r{" fnKey "}"), Sleep(40), Send("r")
  802. else ; When both LButton and RButton are being pressed down then there are no issues (it will intentionally rotate both the character and the camera)
  803. Send("{" fnKey "}")
  804.  
  805. SetTimer((*) => Hotkey("$4", "Off"), -1) ; Makes it use the faster native fn instead of being postponeable (after any postponed ones have been sent)
  806. aboutFace.IsActive := false
  807. }
  808.  
  809.  
  810. *********************************************************************************************************************************************************************************************
  811. MODIFIED AT: 4/22/24 >> desktop shortcut properties for AHKv1.txt:
  812.  
  813. shortcut on desktop was set to
  814. target: "C:\Users\loren\Downloads\AutoHotkey\Guild Wars 2\Guild Wars 2 - NEW 5.ahk"
  815. start in: C:\Users\loren\Downloads\AutoHotKey
  816.  
  817.  
  818. *********************************************************************************************************************************************************************************************
  819. MODIFIED AT: 9/14/22 >> Guild Wars 2 - NEW 2 (backup containing some more code that didn't rly seem necessary).ahk:
  820.  
  821. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  822. ; #Warn ; Enable warnings to assist with detecting common errors.
  823. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  824. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  825.  
  826. ; Any attempt to launch this script when it's already running will be ignored (skips the dialog box and leaves the old instance running)
  827. #SingleInstance Ignore
  828.  
  829. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  830. #InstallMouseHook
  831.  
  832. ; The code below only executes for the Guild Wars 2 window
  833. #IfWinActive Guild Wars 2
  834.  
  835. ; These hotkeys aren't needed straight away and can be turned on when any of these hotkeys actually need to be used
  836. HotKey, LButton, Off
  837. HotKey, RButton, Off
  838.  
  839. ToggleHotkeys()
  840. {
  841. HotKey, v, Toggle
  842. HotKey, F3, Toggle
  843. HotKey, F4, Toggle
  844. HotKey, LButton, Toggle
  845. }
  846.  
  847. ; Suspends hotkeys when making the input field of the chat active with the Enter key (and it will unsuspend the hotkeys when Enter is pressed again)
  848. Enter::
  849. ToggleHotkeys()
  850. Send, {Enter}
  851. return
  852.  
  853. ; Dodge Jump
  854. ~v::Send, {Space}
  855.  
  856. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  857. WiggleCamera()
  858. {
  859. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  860. SetMouseDelay, 1
  861.  
  862. SendEvent {Click -15 0 0 Relative}
  863. SendEvent {Click 15 0 0 Relative}
  864. }
  865.  
  866. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  867. LButtonAboutFace(functionKey)
  868. {
  869. Critical
  870. MouseGetPos, initialCursorX, initialCursorY
  871. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  872.  
  873. if (GetKeyState("LButton") and GetKeyState("RButton"))
  874. Send, {%functionKey%}
  875. else if (GetKeyState("LButton"))
  876. {
  877. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  878. Send, {LButton up}
  879. Sleep, 40
  880. Send, {LButton down}
  881.  
  882. WiggleCamera()
  883. Send, {%functionKey%}
  884. }
  885. else if (GetKeyState("RButton"))
  886. {
  887. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  888. Send, {RButton up}
  889. Send, {RButton down}
  890.  
  891. WiggleCamera()
  892.  
  893. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  894. Send, {RButton up}
  895. HotKey, RButton, On
  896.  
  897. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  898. Click, %windowWidth% %windowY% Down
  899. Send, {%functionKey%}
  900. Click, Up
  901. SendEvent {Click %initialCursorX% %initialCursorY% 0}
  902.  
  903. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  904. if (GetKeyState("RButton", "P"))
  905. {
  906. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  907. Sleep, 525
  908.  
  909. if (GetKeyState("RButton", "P"))
  910. Send, {RButton down}
  911. }
  912.  
  913. HotKey, RButton, Off
  914. }
  915. else
  916. {
  917. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  918. HotKey, RButton, On
  919. Click, %windowWidth% %windowY% Down
  920. WiggleCamera()
  921. Send, {%functionKey%}
  922. Click, Up
  923. SendEvent {Click %initialCursorX% %initialCursorY% 0}
  924. HotKey, RButton, Off
  925. }
  926. }
  927. F3::
  928. F4::LButtonAboutFace("F3")
  929.  
  930. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  931. 4::Send, {4}
  932.  
  933. '::
  934. useMountUpCode := !useMountUpCode ; Toggled boolean variable that becomes true when mounting up
  935.  
  936. if (useMountUpCode)
  937. {
  938. if (GetKeyState("LButton", "P") and GetKeyState("RButton", "P")) ; IF physically pressed down both mouse buttons
  939. {
  940. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  941. Send, {'} ; Mount up while the mouse buttons are still pressed in
  942. return
  943. }
  944. else if (GetKeyState("RButton", "P")) ; IF physically pressed down right mouse button
  945. {
  946. Send, {LButton up}{RButton up} ; Removes glitchy auto-run behaviour where it suddenly stops
  947. Sleep, 25 ; Removes glitchy auto-run behaviour where it suddenly stops
  948. Send, {LButton down}{RButton down} ; Press both mouse buttons (prevents stopping active auto-run permanently below by stopping it temporarily)
  949.  
  950. WiggleCamera() ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user
  951. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  952.  
  953. if (GetKeyState("LButton", "P") and GetKeyState("RButton", "P")) ; IF physically pressed down both mouse buttons
  954. Send, {'} ; Mount up while the mouse buttons are still pressed in
  955. else
  956. { ; ELSE executing code of this scope
  957. Send, {'} ; Mount up while the mouse buttons are still pressed in
  958. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  959. Send, {LButton up} ; Release left mouse button
  960. Send, {r} ; Use auto-run instead
  961. }
  962.  
  963. return
  964. }
  965. else ; ELSE
  966. {
  967. Send, {LButton down}{RButton down} ; Press both mouse buttons
  968. WiggleCamera() ; Wiggling camera to make mouse control work when done by the user
  969. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  970. Send, {'} ; Mount up while the mouse buttons are still pressed in
  971. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  972.  
  973. if (GetKeyState("LButton", "P") and GetKeyState("RButton", "P")) ; IF physically pressed down both mouse buttons
  974. return ; Keep holding both mouse buttons
  975. else ; ELSE
  976. Send, {LButton up}{RButton up} ; Release both mouse buttons
  977. }
  978. }
  979. else
  980. Send, {'} ; Use default behaviour when mounting down
  981.  
  982. return
  983.  
  984. ; Left-click outside the chat area (when this hotkey gets enabled, is off by default) will unsuspend the disabled hotkeys as well, because they only need to stay disabled while chatting
  985. ~LButton::
  986. MouseGetPos, currentCursorX, currentCursorY
  987. if (currentCursorX > 490 or currentCursorY < 1147)
  988. ToggleHotkeys()
  989. return
  990.  
  991. ; The right mouse button can be manually disabled by turning this hotkey on
  992. RButton::return
  993.  
  994.  
  995. *********************************************************************************************************************************************************************************************
  996. MODIFIED AT: 9/15/22 >> Guild Wars 2 - NEW 2.ahk:
  997.  
  998. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  999. ; #Warn ; Enable warnings to assist with detecting common errors.
  1000. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  1001. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  1002.  
  1003. ; Any attempt to launch this script when it's already running will be ignored (skips the dialog box and leaves the old instance running)
  1004. #SingleInstance Ignore
  1005.  
  1006. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  1007. #InstallMouseHook
  1008.  
  1009. ; The code below only executes for the Guild Wars 2 window
  1010. #IfWinActive Guild Wars 2
  1011.  
  1012. ; These hotkeys aren't needed straight away and can be turned on when any of these hotkeys actually need to be used
  1013. HotKey, LButton, Off
  1014. HotKey, RButton, Off
  1015.  
  1016. ToggleHotkeys()
  1017. {
  1018. HotKey, v, Toggle
  1019. HotKey, F3, Toggle
  1020. HotKey, F4, Toggle
  1021. HotKey, LButton, Toggle
  1022. }
  1023.  
  1024. ; Suspends hotkeys when making the input field of the chat active with the Enter key (and it will unsuspend the hotkeys when Enter is pressed again)
  1025. Enter::
  1026. ToggleHotkeys()
  1027. Send, {Enter}
  1028. return
  1029.  
  1030. ; Dodge Jump
  1031. ~v::Send, {Space}
  1032.  
  1033. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  1034. WiggleCamera()
  1035. {
  1036. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  1037. SetMouseDelay, 1
  1038.  
  1039. SendEvent {Click -15 0 0 Relative}
  1040. SendEvent {Click 15 0 0 Relative}
  1041. }
  1042.  
  1043. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  1044. LButtonAboutFace(functionKey)
  1045. {
  1046. Critical
  1047. MouseGetPos, initialCursorX, initialCursorY
  1048. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  1049.  
  1050. if (GetKeyState("LButton") and GetKeyState("RButton"))
  1051. Send, {%functionKey%}
  1052. else if (GetKeyState("LButton"))
  1053. {
  1054. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  1055. Send, {LButton up}
  1056. Sleep, 40
  1057. Send, {LButton down}
  1058.  
  1059. WiggleCamera()
  1060. Send, {%functionKey%}
  1061. }
  1062. else if (GetKeyState("RButton"))
  1063. {
  1064. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  1065. Send, {RButton up}
  1066. Send, {RButton down}
  1067.  
  1068. WiggleCamera()
  1069.  
  1070. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  1071. Send, {RButton up}
  1072. HotKey, RButton, On
  1073.  
  1074. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1075. Click, %windowWidth% %windowY% Down
  1076. Send, {%functionKey%}
  1077. Click, Up
  1078. SendEvent {Click %initialCursorX% %initialCursorY% 0}
  1079.  
  1080. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  1081. if (GetKeyState("RButton", "P"))
  1082. {
  1083. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  1084. Sleep, 525
  1085.  
  1086. if (GetKeyState("RButton", "P"))
  1087. Send, {RButton down}
  1088. }
  1089.  
  1090. HotKey, RButton, Off
  1091. }
  1092. else
  1093. {
  1094. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1095. HotKey, RButton, On
  1096. Click, %windowWidth% %windowY% Down
  1097. WiggleCamera()
  1098. Send, {%functionKey%}
  1099. Click, Up
  1100. SendEvent {Click %initialCursorX% %initialCursorY% 0}
  1101. HotKey, RButton, Off
  1102. }
  1103. }
  1104. F3::
  1105. F4::LButtonAboutFace("F3")
  1106.  
  1107. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  1108. 4::Send, {4}
  1109.  
  1110. ; This fixes the bug where the character suddenly rotates in a random manner when the player goes on their mount while auto-run is active and the right mouse button is being pressed
  1111. '::
  1112. isMountUpAction := !isMountUpAction ; Toggled boolean variable that becomes true when mounting up
  1113.  
  1114. if (isMountUpAction and GetKeyState("RButton", "P") and !GetKeyState("LButton", "P")) ; IF physically pressed down right mouse button but not left mouse button
  1115. {
  1116. Send, {LButton up}{RButton up} ; Removes glitchy auto-run behaviour where it suddenly stops
  1117. Sleep, 25 ; Removes glitchy auto-run behaviour where it suddenly stops
  1118. Send, {LButton down}{RButton down} ; Press both mouse buttons (prevents auto-run from being stopped accidentally later on)
  1119.  
  1120. WiggleCamera() ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user
  1121. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  1122.  
  1123. if (GetKeyState("LButton", "P") and GetKeyState("RButton", "P")) ; IF physically pressed down both mouse buttons
  1124. Send, {'} ; Mount up while the mouse buttons are still pressed in
  1125. else
  1126. { ; ELSE executing code of this scope
  1127. Send, {'} ; Mount up while the mouse buttons are still pressed in
  1128. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  1129. Send, {LButton up} ; Release left mouse button
  1130. Send, {r} ; Use auto-run instead
  1131. }
  1132. }
  1133. else
  1134. Send, {'} ; Use default behaviour when mounting down and when other key state combinations are detected
  1135.  
  1136. return
  1137.  
  1138. ; Left-click outside the chat area (when this hotkey gets enabled, is off by default) will unsuspend the disabled hotkeys as well, because they only need to stay disabled while chatting
  1139. ~LButton::
  1140. MouseGetPos, currentCursorX, currentCursorY
  1141. if (currentCursorX > 490 or currentCursorY < 1147)
  1142. ToggleHotkeys()
  1143. return
  1144.  
  1145. ; The right mouse button can be manually disabled by turning this hotkey on
  1146. RButton::return
  1147.  
  1148.  
  1149. *********************************************************************************************************************************************************************************************
  1150. MODIFIED AT: 9/23/22 >> Guild Wars 2 - NEW 3 - Custom auto-run,-fly that doesn't work very well.ahk:
  1151.  
  1152. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  1153. ; #Warn ; Enable warnings to assist with detecting common errors.
  1154. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  1155. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  1156.  
  1157. ; Any attempt to launch this script when it's already running will be ignored (skips the dialog box and leaves the old instance running)
  1158. #SingleInstance Ignore
  1159.  
  1160. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  1161. #InstallMouseHook
  1162.  
  1163. isChatActive := false
  1164. isCustomAutoRunTemporarilyDisabled := false
  1165. isCustomAutoRunEnabled := false
  1166.  
  1167. ; These hotkeys aren't needed straight away and can be turned on when they need to be used (so here they get turned off as their default state)
  1168. ToggleMovementHotkeys(true)
  1169. HotKey, RButton, Off
  1170.  
  1171. ; Runs the game and terminates the macro when the game window doesn't exist any longer (keep this at the bottom of the auto-execute section)
  1172. ;RunWait, "C:\Program Files\Guild Wars 2\Gw2-64.exe"
  1173. ;ExitApp
  1174.  
  1175. LeftMouseButtonBaseAction(skipMovementHotkeysToggle := false)
  1176. {
  1177. Global
  1178.  
  1179. if (GetKeyState("LButton", "P"))
  1180. {
  1181. Send, {LButton down}
  1182.  
  1183. Loop, 5
  1184. {
  1185. if (GetKeyState("RButton", "P"))
  1186. {
  1187. isCustomAutoRunEnabled := false
  1188. Send, {w up}
  1189.  
  1190. if (!skipMovementHotkeysToggle)
  1191. ToggleMovementHotkeys()
  1192.  
  1193. Break
  1194. }
  1195.  
  1196. Sleep, 100
  1197. }
  1198.  
  1199. KeyWait, LButton
  1200. Send, {LButton up}
  1201. }
  1202. else
  1203. Send, {LButton}
  1204. }
  1205.  
  1206. ToggleChatState(shouldSendLButtonManually, shouldSendEnterManually)
  1207. {
  1208. Global
  1209.  
  1210. if (isCustomAutoRunTemporarilyDisabled)
  1211. {
  1212. ; Closing the chat (LButton down is used sometimes and won't close the chat)
  1213. Send, {Enter}
  1214.  
  1215. if (shouldSendLButtonManually)
  1216. LeftMouseButtonBaseAction(true)
  1217.  
  1218. ; Use custom auto-run again if the method above didn't disable it
  1219. if (isCustomAutoRunEnabled)
  1220. {
  1221. Send, {w up}
  1222. Send, {w down}
  1223.  
  1224. ToggleMovementHotkeys()
  1225. isCustomAutoRunTemporarilyDisabled := false
  1226. }
  1227. }
  1228. else if (isCustomAutoRunEnabled)
  1229. {
  1230. ; Use normal auto-run instead (temporarily)
  1231. Send, {F10}
  1232.  
  1233. ; Opening the chat (LButton is not necessary here)
  1234. Send, {Enter}
  1235.  
  1236. isCustomAutoRunTemporarilyDisabled := true
  1237. ToggleMovementHotkeys()
  1238. }
  1239. else if (!shouldSendLButtonManually and shouldSendEnterManually)
  1240. Send, {Enter}
  1241.  
  1242. HotKey, r, Toggle
  1243. HotKey, t, Toggle
  1244. HotKey, v, Toggle
  1245. isChatActive := !isChatActive
  1246. }
  1247.  
  1248. LeftMouseButtonAction(shouldSendLButtonManually)
  1249. {
  1250. Global
  1251. MouseGetPos, currentCursorX, currentCursorY
  1252.  
  1253. if (isChatActive)
  1254. {
  1255. if (currentCursorX > 490 or currentCursorY < 1147)
  1256. ToggleChatState(shouldSendLButtonManually, false)
  1257. }
  1258. else if (currentCursorX < 482 and currentCursorY > 1370)
  1259. ToggleChatState(shouldSendLButtonManually, false)
  1260. else if (shouldSendLButtonManually)
  1261. LeftMouseButtonBaseAction()
  1262. }
  1263.  
  1264. ; The code below only executes for the Guild Wars 2 window when custom auto-run is enabled
  1265. #If (WinActive("Guild Wars 2") and isCustomAutoRunEnabled)
  1266.  
  1267. ; Left-click outside the chat area with an active chat input field and left-click inside an inactive chat input field both toggles the chat state of the macro as well
  1268. LButton::LeftMouseButtonAction(true)
  1269.  
  1270. ; The code below only executes for the Guild Wars 2 window when custom auto-run is disabled
  1271. #If (WinActive("Guild Wars 2") and !isCustomAutoRunEnabled)
  1272.  
  1273. ; Left-click outside the chat area with an active chat input field and left-click inside an inactive chat input field both toggles the chat state of the macro as well
  1274. ~LButton::LeftMouseButtonAction(false)
  1275.  
  1276. ; The code below only executes for the Guild Wars 2 window
  1277. #If (WinActive("Guild Wars 2"))
  1278.  
  1279. ; Prevents hotkey interference when the chat is being used and vice versa
  1280. Enter::ToggleChatState(false, true)
  1281.  
  1282. ; Dodge Jump
  1283. ~v::Send, {Space}
  1284.  
  1285. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  1286. WiggleCamera()
  1287. {
  1288. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  1289. SetMouseDelay, 1
  1290.  
  1291. Send, {Click -15 0 0 Relative}
  1292. Send, {Click 15 0 0 Relative}
  1293. }
  1294.  
  1295. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  1296. LButtonAboutFace(functionKey)
  1297. {
  1298. Critical
  1299. MouseGetPos, initialCursorX, initialCursorY
  1300. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  1301.  
  1302. if (GetKeyState("LButton") and GetKeyState("RButton"))
  1303. Send, {%functionKey%}
  1304. else if (GetKeyState("LButton"))
  1305. {
  1306. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  1307. Send, {LButton up}
  1308. Sleep, 40
  1309. Send, {LButton down}
  1310.  
  1311. WiggleCamera()
  1312. Send, {%functionKey%}
  1313. }
  1314. else if (GetKeyState("RButton"))
  1315. {
  1316. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  1317. Send, {RButton up}
  1318. Send, {RButton down}
  1319.  
  1320. WiggleCamera()
  1321.  
  1322. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  1323. Send, {RButton up}
  1324. HotKey, RButton, On
  1325.  
  1326. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1327. Click, %windowWidth% %windowY% Down
  1328. Send, {%functionKey%}
  1329. Click, Up
  1330. Send, {Click %initialCursorX% %initialCursorY% 0}
  1331.  
  1332. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  1333. if (GetKeyState("RButton", "P"))
  1334. {
  1335. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  1336. Sleep, 525
  1337.  
  1338. if (GetKeyState("RButton", "P"))
  1339. Send, {RButton down}
  1340. }
  1341.  
  1342. HotKey, RButton, Off
  1343. }
  1344. else
  1345. {
  1346. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1347. HotKey, RButton, On
  1348. Click, %windowWidth% %windowY% Down
  1349. WiggleCamera()
  1350. Send, {%functionKey%}
  1351. Click, Up
  1352. Send, {Click %initialCursorX% %initialCursorY% 0}
  1353. HotKey, RButton, Off
  1354. }
  1355. }
  1356.  
  1357. F3::
  1358. F4::LButtonAboutFace("F3")
  1359.  
  1360. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  1361. 4::Send, {4}
  1362.  
  1363. ToggleMovementHotkeys(skipCustomAutoRunHotkeys := false)
  1364. {
  1365. HotKey, w, Toggle
  1366. HotKey, s, Toggle
  1367.  
  1368. if (!skipCustomAutoRunHotkeys)
  1369. {
  1370. HotKey, r, Toggle
  1371. HotKey, t, Toggle
  1372. }
  1373. }
  1374.  
  1375. ; These movement hotkeys will also stop the custom auto-run effect
  1376. ~w::
  1377. isCustomAutoRunEnabled := false
  1378. ToggleMovementHotkeys()
  1379. return
  1380. ~s::
  1381. isCustomAutoRunEnabled := false
  1382. Send, {w up}
  1383. ToggleMovementHotkeys()
  1384. return
  1385.  
  1386. r::
  1387. t::
  1388. ; This will prevent the forward movement hotkey action (one that might've been done earlier in this frame or an older frame), to cause this auto-run action not to work
  1389. if (GetKeyState("w") or GetKeyState("w", "P"))
  1390. {
  1391. KeyWait, w
  1392. Sleep, 500
  1393. }
  1394. ;else ; this code below doesn't fix 2..* restarts, and doesn't seem to matter what I try..
  1395. {
  1396. Send, {w up}
  1397. Sleep, 200
  1398. Send, {w down}
  1399. Sleep, 300
  1400. Send, {w up}
  1401. Sleep, 200
  1402. ;Send, {w}
  1403. ;Send, {s}
  1404. ;Send, {s down}
  1405. ;Sleep, 500
  1406. ;Send, {s up}
  1407. }
  1408.  
  1409. Send, {w down}
  1410.  
  1411. if (isCustomAutoRunEnabled)
  1412. ToggleMovementHotkeys()
  1413.  
  1414. isCustomAutoRunEnabled := true
  1415. return
  1416.  
  1417. ; This fixes the bug where the character suddenly rotates in a random manner when the player goes on their mount while auto-run is active and the right mouse button is being pressed
  1418. ~'::
  1419. ; Toggled boolean variable that becomes true when mounting up
  1420. isMountUpAction := !isMountUpAction
  1421.  
  1422. ; This is for when the player actually mounts up and is physically pressing the right mouse button but not the left mouse button (aka the situation where the bug happens)
  1423. if (isMountUpAction and GetKeyState("RButton", "P") and !GetKeyState("LButton", "P"))
  1424. {
  1425. ; The best cursor placement to have when the mouse buttons are no longer pressed and the center of the screen also guarantees the code to work
  1426. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  1427. halfWindowWidth := windowWidth / 2
  1428. halfWindowHeight := windowHeight / 2
  1429.  
  1430. ; This is also necessary to make the original bugfix work and a high sleep time helps the user with regaining camera control automatically
  1431. Send, {RButton up}
  1432. Sleep, 100
  1433.  
  1434. ; Press both mouse buttons (prevents auto-run from being stopped accidentally later on and this also makes wiggling the camera possible)
  1435. Send, {Click %halfWindowWidth% %halfWindowHeight% Down}{RButton down}
  1436.  
  1437. ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user and holding both mouse buttons for atleast 50 milliseconds longer
  1438. WiggleCamera()
  1439. Sleep, 50
  1440.  
  1441. ; Executes code for physical mouse button state combinations (when both mouse buttons are physically pressed then it'll simply return without releasing them)
  1442. if (!GetKeyState("LButton", "P") and GetKeyState("RButton", "P"))
  1443. {
  1444. ; Release left mouse button and use auto-run instead
  1445. Send, {LButton up}
  1446. Send, {r}
  1447. }
  1448. else if (!GetKeyState("LButton", "P") and !GetKeyState("RButton", "P"))
  1449. ; Releases both mouse buttons
  1450. Send, {LButton up}{RButton up}
  1451. }
  1452.  
  1453. return
  1454.  
  1455. ; The right mouse button can be manually disabled by turning this hotkey on
  1456. RButton::return
  1457.  
  1458.  
  1459. *********************************************************************************************************************************************************************************************
  1460. MODIFIED AT: 9/19/22 >> Guild Wars 2 - NEW 3 - SetTimer.ahk:
  1461.  
  1462. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  1463. ; #Warn ; Enable warnings to assist with detecting common errors.
  1464. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  1465. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  1466.  
  1467. ; Any attempt to launch this script when it's already running will be ignored (skips the dialog box and leaves the old instance running)
  1468. #SingleInstance Ignore
  1469.  
  1470. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  1471. #InstallMouseHook
  1472.  
  1473. Run, "C:\Program Files\Guild Wars 2\Gw2-64.exe"
  1474.  
  1475. ; Terminates the macro when the game window doesn't exist any longer
  1476. TerminateAutomatically()
  1477. {
  1478. if (!WinExist("Guild Wars 2"))
  1479. ExitApp
  1480. }
  1481.  
  1482. ; Checks every 10 minutes if the macro can be terminated and invokes the method when it can
  1483. SetTimer, TerminateAutomatically, 600000
  1484.  
  1485. ; The code below only executes for the Guild Wars 2 window
  1486. #IfWinActive Guild Wars 2
  1487.  
  1488. ; This hotkey isn't needed straight away and can be turned on when it needs to be used
  1489. HotKey, RButton, Off
  1490.  
  1491. ToggleChatState()
  1492. {
  1493. HotKey, v, Toggle
  1494. global isChatActive := !isChatActive
  1495. }
  1496.  
  1497. ; Prevents hotkey interference when the chat is being used
  1498. ~Enter::ToggleChatState()
  1499.  
  1500. ; Dodge Jump
  1501. ~v::Send, {Space}
  1502.  
  1503. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  1504. WiggleCamera()
  1505. {
  1506. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  1507. SetMouseDelay, 1
  1508.  
  1509. Send, {Click -15 0 0 Relative}
  1510. Send, {Click 15 0 0 Relative}
  1511. }
  1512.  
  1513. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  1514. LButtonAboutFace(functionKey)
  1515. {
  1516. Critical
  1517. MouseGetPos, initialCursorX, initialCursorY
  1518. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  1519.  
  1520. if (GetKeyState("LButton") and GetKeyState("RButton"))
  1521. Send, {%functionKey%}
  1522. else if (GetKeyState("LButton"))
  1523. {
  1524. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  1525. Send, {LButton up}
  1526. Sleep, 40
  1527. Send, {LButton down}
  1528.  
  1529. WiggleCamera()
  1530. Send, {%functionKey%}
  1531. }
  1532. else if (GetKeyState("RButton"))
  1533. {
  1534. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  1535. Send, {RButton up}
  1536. Send, {RButton down}
  1537.  
  1538. WiggleCamera()
  1539.  
  1540. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  1541. Send, {RButton up}
  1542. HotKey, RButton, On
  1543.  
  1544. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1545. Click, %windowWidth% %windowY% Down
  1546. Send, {%functionKey%}
  1547. Click, Up
  1548. Send, {Click %initialCursorX% %initialCursorY% 0}
  1549.  
  1550. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  1551. if (GetKeyState("RButton", "P"))
  1552. {
  1553. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  1554. Sleep, 525
  1555.  
  1556. if (GetKeyState("RButton", "P"))
  1557. Send, {RButton down}
  1558. }
  1559.  
  1560. HotKey, RButton, Off
  1561. }
  1562. else
  1563. {
  1564. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1565. HotKey, RButton, On
  1566. Click, %windowWidth% %windowY% Down
  1567. WiggleCamera()
  1568. Send, {%functionKey%}
  1569. Click, Up
  1570. Send, {Click %initialCursorX% %initialCursorY% 0}
  1571. HotKey, RButton, Off
  1572. }
  1573. }
  1574.  
  1575. F3::
  1576. F4::LButtonAboutFace("F3")
  1577.  
  1578. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  1579. 4::Send, {4}
  1580.  
  1581. ; This fixes the bug where the character suddenly rotates in a random manner when the player goes on their mount while auto-run is active and the right mouse button is being pressed
  1582. ~'::
  1583. ; Toggled boolean variable that becomes true when mounting up
  1584. isMountUpAction := !isMountUpAction
  1585.  
  1586. ; This is for when the player actually mounts up and is physically pressing the right mouse button but not the left mouse button (aka the situation where the bug happens)
  1587. if (isMountUpAction and GetKeyState("RButton", "P") and !GetKeyState("LButton", "P"))
  1588. {
  1589. ; The best cursor placement to have when the mouse buttons are no longer pressed and the center of the screen also guarantees the code to work
  1590. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  1591. halfWindowWidth := windowWidth / 2
  1592. halfWindowHeight := windowHeight / 2
  1593.  
  1594. ; This is also necessary to make the original bugfix work and a high sleep time helps the user with regaining camera control automatically
  1595. Send, {RButton up}
  1596. Sleep, 100
  1597.  
  1598. ; Press both mouse buttons (prevents auto-run from being stopped accidentally later on and this also makes wiggling the camera possible)
  1599. Send, {Click %halfWindowWidth% %halfWindowHeight% Down}{RButton down}
  1600.  
  1601. ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user and holding both mouse buttons for atleast 50 milliseconds longer
  1602. WiggleCamera()
  1603. Sleep, 50
  1604.  
  1605. ; Executes code for physical mouse button state combinations (when both mouse buttons are physically pressed then it'll simply return without releasing them)
  1606. if (!GetKeyState("LButton", "P") and GetKeyState("RButton", "P"))
  1607. {
  1608. ; Release left mouse button and use auto-run instead
  1609. Send, {LButton up}
  1610. Send, {r}
  1611. }
  1612. else if (!GetKeyState("LButton", "P") and !GetKeyState("RButton", "P"))
  1613. ; Releases both mouse buttons
  1614. Send, {LButton up}{RButton up}
  1615. }
  1616.  
  1617. return
  1618.  
  1619. ; Left-click outside the chat area with an active chat input field and left-click inside an inactive chat input field both toggles the chat state of the macro as well
  1620. ~LButton::
  1621. MouseGetPos, currentCursorX, currentCursorY
  1622.  
  1623. if (isChatActive)
  1624. {
  1625. if (currentCursorX > 490 or currentCursorY < 1147)
  1626. ToggleChatState()
  1627. }
  1628. else if (currentCursorX < 482 and currentCursorY > 1370)
  1629. ToggleChatState()
  1630.  
  1631. return
  1632.  
  1633. ; The right mouse button can be manually disabled by turning this hotkey on
  1634. RButton::return
  1635.  
  1636.  
  1637. *********************************************************************************************************************************************************************************************
  1638. MODIFIED AT: 10/11/22 6:44 PM >> Guild Wars 2 - NEW 3.ahk:
  1639.  
  1640. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  1641. ; #Warn ; Enable warnings to assist with detecting common errors.
  1642. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  1643. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  1644.  
  1645. ; Any attempt to launch this script when it's already running will reload it (the dialog box that normally appears in this situation gets skipped)
  1646. #SingleInstance Force
  1647.  
  1648. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  1649. #InstallMouseHook
  1650.  
  1651. ; This hotkey isn't needed straight away and can be turned on when it needs to be used
  1652. HotKey, RButton, Off
  1653.  
  1654. ; Terminates the macro if the game doesn't restart itself within 30 seconds. And also has recursive code, which restarts this method each time the game crashes and immediately restarts
  1655. ManageApp()
  1656. {
  1657. WinWait, Guild Wars 2,, 30
  1658.  
  1659. if (ErrorLevel == 1)
  1660. ExitApp
  1661. else
  1662. {
  1663. WinWaitClose
  1664. ManageApp()
  1665. }
  1666. }
  1667.  
  1668. ; Runs the game and terminates the macro when the game window doesn't exist any longer and wasn't being restarted either (keep this at the bottom of the auto-execute section)
  1669. RunWait, "C:\Program Files\Guild Wars 2\Gw2-64.exe"
  1670. ManageApp()
  1671.  
  1672. ; The code below only executes for the Guild Wars 2 window
  1673. #IfWinActive Guild Wars 2
  1674.  
  1675. ToggleChatState()
  1676. {
  1677. HotKey, v, Toggle
  1678. global isChatActive := !isChatActive
  1679. }
  1680.  
  1681. ; Prevents hotkey interference when the chat is being used
  1682. ~Enter::ToggleChatState()
  1683.  
  1684. ; Dodge Jump
  1685. ~v::Send, {Space}
  1686.  
  1687. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  1688. WiggleCamera()
  1689. {
  1690. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  1691. SetMouseDelay, 1
  1692.  
  1693. Send, {Click -15 0 0 Relative}
  1694. Send, {Click 15 0 0 Relative}
  1695. }
  1696.  
  1697. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  1698. LButtonAboutFace(functionKey)
  1699. {
  1700. Critical
  1701. MouseGetPos, initialCursorX, initialCursorY
  1702. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  1703.  
  1704. if (GetKeyState("LButton") and GetKeyState("RButton"))
  1705. Send, {%functionKey%}
  1706. else if (GetKeyState("LButton"))
  1707. {
  1708. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  1709. Send, {LButton up}
  1710. Sleep, 40
  1711. Send, {LButton down}
  1712.  
  1713. WiggleCamera()
  1714. Send, {%functionKey%}
  1715. }
  1716. else if (GetKeyState("RButton"))
  1717. {
  1718. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  1719. Send, {RButton up}
  1720. Send, {RButton down}
  1721.  
  1722. WiggleCamera()
  1723.  
  1724. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  1725. Send, {RButton up}
  1726. HotKey, RButton, On
  1727.  
  1728. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1729. Click, %windowWidth% %windowY% Down
  1730. Send, {%functionKey%}
  1731. Click, Up
  1732. Send, {Click %initialCursorX% %initialCursorY% 0}
  1733.  
  1734. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  1735. if (GetKeyState("RButton", "P"))
  1736. {
  1737. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  1738. Sleep, 525
  1739.  
  1740. if (GetKeyState("RButton", "P"))
  1741. Send, {RButton down}
  1742. }
  1743.  
  1744. HotKey, RButton, Off
  1745. }
  1746. else
  1747. {
  1748. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1749. HotKey, RButton, On
  1750. Click, %windowWidth% %windowY% Down
  1751. WiggleCamera()
  1752. Send, {%functionKey%}
  1753. Click, Up
  1754. Send, {Click %initialCursorX% %initialCursorY% 0}
  1755. HotKey, RButton, Off
  1756. }
  1757. }
  1758.  
  1759. F3::
  1760. F4::LButtonAboutFace("F3")
  1761.  
  1762. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  1763. 4::Send, {4}
  1764.  
  1765. ; This fixes the bug where the character suddenly rotates in a random manner when the player goes on their mount while auto-run is active and the right mouse button is being pressed
  1766. ~'::
  1767. ; Toggled boolean variable that becomes true when mounting up
  1768. isMountUpAction := !isMountUpAction
  1769.  
  1770. ; This is for when the player actually mounts up and is physically pressing the right mouse button but not the left mouse button (aka the situation where the bug happens)
  1771. if (isMountUpAction and GetKeyState("RButton", "P") and !GetKeyState("LButton", "P"))
  1772. {
  1773. Critical
  1774.  
  1775. ; The best cursor placement to have when the mouse buttons are no longer pressed and the center of the screen also guarantees the code to work
  1776. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  1777. halfWindowWidth := windowWidth / 2
  1778. halfWindowHeight := windowHeight / 2
  1779.  
  1780. ; This is also necessary to make the original bugfix work and a high sleep time helps the user with regaining camera control automatically
  1781. Send, {RButton up}
  1782. Sleep, 100
  1783.  
  1784. ; Press both mouse buttons (prevents auto-run from being stopped accidentally later on and this also makes wiggling the camera possible)
  1785. Send, {Click %halfWindowWidth% %halfWindowHeight% Down}{RButton down}
  1786.  
  1787. ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user and holding both mouse buttons for atleast 50 milliseconds longer
  1788. WiggleCamera()
  1789. Sleep, 50
  1790.  
  1791. ; Executes code for physical mouse button state combinations (when both mouse buttons are physically pressed then it'll simply return without releasing them)
  1792. if (!GetKeyState("LButton", "P") and GetKeyState("RButton", "P"))
  1793. {
  1794. ; Release left mouse button and use auto-run instead
  1795. Send, {LButton up}
  1796. Send, {r}
  1797. }
  1798. else if (!GetKeyState("LButton", "P") and !GetKeyState("RButton", "P"))
  1799. ; Releases both mouse buttons
  1800. Send, {LButton up}{RButton up}
  1801. }
  1802.  
  1803. return
  1804.  
  1805. ; Left-click outside the chat area with an active chat input field and left-click inside an inactive chat input field both toggles the chat state of the macro as well
  1806. ~LButton::
  1807. MouseGetPos, currentCursorX, currentCursorY
  1808.  
  1809. if (isChatActive)
  1810. {
  1811. if (currentCursorX > 490 or currentCursorY < 1147)
  1812. ToggleChatState()
  1813. }
  1814. else if (currentCursorX < 482 and currentCursorY > 1370)
  1815. ToggleChatState()
  1816.  
  1817. return
  1818.  
  1819. ; The right mouse button can be manually disabled by turning this hotkey on
  1820. RButton::return
  1821.  
  1822.  
  1823. *********************************************************************************************************************************************************************************************
  1824. MODIFIED AT: 10/11/22 7:33 PM >> Guild Wars 2 - NEW 4 (backup containing some more code that didn't rly seem necessary).ahk:
  1825.  
  1826. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  1827. ; #Warn ; Enable warnings to assist with detecting common errors.
  1828. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  1829. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  1830.  
  1831. ; Any attempt to launch this script when it's already running will reload it (the dialog box that normally appears in this situation gets skipped)
  1832. #SingleInstance Force
  1833.  
  1834. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  1835. #InstallMouseHook
  1836.  
  1837. ; Terminates the macro if the game doesn't restart itself within 30 seconds. And also has recursive code, which restarts this method each time the game crashes and immediately restarts
  1838. ManageApp()
  1839. {
  1840. WinWait, Guild Wars 2,, 30
  1841.  
  1842. if (ErrorLevel == 1)
  1843. ExitApp
  1844. else
  1845. {
  1846. WinWaitClose
  1847. ManageApp()
  1848. }
  1849. }
  1850.  
  1851. ; Runs the game and terminates the macro when the game window doesn't exist any longer and wasn't being restarted either (keep this at the bottom of the auto-execute section)
  1852. RunWait, "C:\Program Files\Guild Wars 2\Gw2-64.exe"
  1853. ManageApp()
  1854.  
  1855. ; The code below only executes for the Guild Wars 2 window
  1856. #If (WinActive("Guild Wars 2"))
  1857.  
  1858. ToggleChatState()
  1859. {
  1860. HotKey, v, Toggle
  1861. global isChatActive := !isChatActive
  1862. }
  1863.  
  1864. ; Prevents hotkey interference when the chat is being used
  1865. ~Enter::ToggleChatState()
  1866.  
  1867. ; Dodge Jump
  1868. ~v::Send, {Space}
  1869.  
  1870. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  1871. WiggleCamera()
  1872. {
  1873. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  1874. SetMouseDelay, 1
  1875.  
  1876. Send, {Click -15 0 0 Relative}
  1877. Send, {Click 15 0 0 Relative}
  1878. }
  1879.  
  1880. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  1881. LButtonAboutFace(functionKey)
  1882. {
  1883. Critical
  1884. MouseGetPos, initialCursorX, initialCursorY
  1885. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  1886.  
  1887. if (GetKeyState("LButton") and GetKeyState("RButton"))
  1888. Send, {%functionKey%}
  1889. else if (GetKeyState("LButton"))
  1890. {
  1891. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  1892. Send, {LButton up}
  1893. Sleep, 40
  1894. Send, {LButton down}
  1895.  
  1896. WiggleCamera()
  1897. Send, {%functionKey%}
  1898. }
  1899. else if (GetKeyState("RButton"))
  1900. {
  1901. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  1902. Send, {RButton up}
  1903. Send, {RButton down}
  1904.  
  1905. WiggleCamera()
  1906.  
  1907. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  1908. Send, {RButton up}
  1909. shouldDisableRButton := true
  1910.  
  1911. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1912. Click, %windowWidth% %windowY% Down
  1913. Send, {%functionKey%}
  1914. Click, Up
  1915. Send, {Click %initialCursorX% %initialCursorY% 0}
  1916.  
  1917. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  1918. if (GetKeyState("RButton", "P"))
  1919. {
  1920. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  1921. Sleep, 525
  1922.  
  1923. if (GetKeyState("RButton", "P"))
  1924. Send, {RButton down}
  1925. }
  1926.  
  1927. shouldDisableRButton := false
  1928. }
  1929. else
  1930. {
  1931. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  1932. shouldDisableRButton := true
  1933. Click, %windowWidth% %windowY% Down
  1934. WiggleCamera()
  1935. Send, {%functionKey%}
  1936. Click, Up
  1937. Send, {Click %initialCursorX% %initialCursorY% 0}
  1938. shouldDisableRButton := false
  1939. }
  1940. }
  1941.  
  1942. F3::
  1943. F4::LButtonAboutFace("F3")
  1944.  
  1945. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  1946. 4::Send, {4}
  1947. w::Send, {w}
  1948. a::Send, {a}
  1949. s::Send, {s}
  1950. d::Send, {d}
  1951.  
  1952. ; This fixes the bug where the character suddenly rotates in a random manner when the player goes on their mount while auto-run is active and the right mouse button is being pressed
  1953. ~'::
  1954. ; Toggled boolean variable that becomes true when mounting up
  1955. isMountUpAction := !isMountUpAction
  1956.  
  1957. ; This is for when the player actually mounts up and is physically pressing the right mouse button but not the left mouse button (aka the situation where the bug happens)
  1958. if (isMountUpAction and GetKeyState("RButton", "P") and !GetKeyState("LButton", "P"))
  1959. {
  1960. Critical
  1961.  
  1962. ; The best cursor placement to have when the mouse buttons are no longer pressed and the center of the screen also guarantees the code to work
  1963. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  1964. halfWindowWidth := windowWidth / 2
  1965. halfWindowHeight := windowHeight / 2
  1966.  
  1967. ; This is also necessary to make the original bugfix work and a high sleep time helps the user with regaining camera control automatically
  1968. Send, {RButton up}
  1969. Sleep, 100
  1970.  
  1971. ; Press both mouse buttons (prevents auto-run from being stopped accidentally later on and this also makes wiggling the camera possible)
  1972. Send, {Click %halfWindowWidth% %halfWindowHeight% Down}{RButton down}
  1973.  
  1974. ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user and holding both mouse buttons for atleast 50 milliseconds longer
  1975. WiggleCamera()
  1976. Sleep, 50
  1977.  
  1978. ; Executes code for physical mouse button state combinations (when both mouse buttons are physically pressed then it'll simply return without releasing them)
  1979. if (!GetKeyState("LButton", "P") and GetKeyState("RButton", "P"))
  1980. {
  1981. ; Release left mouse button and use auto-run instead
  1982. Send, {LButton up}
  1983. Send, {r}
  1984. }
  1985. else if (!GetKeyState("LButton", "P") and !GetKeyState("RButton", "P"))
  1986. ; Releases both mouse buttons
  1987. Send, {LButton up}{RButton up}
  1988. }
  1989.  
  1990. return
  1991.  
  1992. ; Left-click outside the chat area with an active chat input field and left-click inside an inactive chat input field both toggles the chat state of the macro as well
  1993. ~LButton::
  1994. MouseGetPos, currentCursorX, currentCursorY
  1995.  
  1996. if (isChatActive)
  1997. {
  1998. if (currentCursorX > 490 or currentCursorY < 1147)
  1999. ToggleChatState()
  2000. }
  2001. else if (currentCursorX < 482 and currentCursorY > 1370)
  2002. ToggleChatState()
  2003.  
  2004. return
  2005.  
  2006. #If (WinActive("Guild Wars 2") and !shouldDisableRButton)
  2007.  
  2008. ; This postpones the right mouse button when an uninterruptible function is being executed (default behaviour)
  2009. RButton::Send, {RButton}
  2010.  
  2011. #If (WinActive("Guild Wars 2") and shouldDisableRButton)
  2012.  
  2013. ; The right mouse button can be manually disabled by turning this hotkey on with the shouldDisableRButton boolean
  2014. RButton::return
  2015.  
  2016.  
  2017. *********************************************************************************************************************************************************************************************
  2018. MODIFIED AT: 10/11/22 7:52 PM >> Guild Wars 2 - NEW 4 (backup of a slower alternative bc ~ symbol isn't used for postponable hotkeys LMB RMB WASD).ahk:
  2019.  
  2020. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2021. ; #Warn ; Enable warnings to assist with detecting common errors.
  2022. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  2023. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  2024.  
  2025. ; Any attempt to launch this script when it's already running will reload it (the dialog box that normally appears in this situation gets skipped)
  2026. #SingleInstance Force
  2027.  
  2028. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  2029. #InstallMouseHook
  2030.  
  2031. ; Terminates the macro if the game doesn't restart itself within 30 seconds. And also has recursive code, which restarts this method each time the game crashes and immediately restarts
  2032. ManageApp()
  2033. {
  2034. WinWait, Guild Wars 2,, 30
  2035.  
  2036. if (ErrorLevel == 1)
  2037. ExitApp
  2038. else
  2039. {
  2040. WinWaitClose
  2041. ManageApp()
  2042. }
  2043. }
  2044.  
  2045. ; Runs the game and terminates the macro when the game window doesn't exist any longer and wasn't being restarted either (keep this at the bottom of the auto-execute section)
  2046. RunWait, "C:\Program Files\Guild Wars 2\Gw2-64.exe"
  2047. ManageApp()
  2048.  
  2049. ; The code below only executes for the Guild Wars 2 window
  2050. #If (WinActive("Guild Wars 2"))
  2051.  
  2052. ToggleChatState()
  2053. {
  2054. HotKey, v, Toggle
  2055. global isChatActive := !isChatActive
  2056. }
  2057.  
  2058. ; Prevents hotkey interference when the chat is being used
  2059. ~Enter::ToggleChatState()
  2060.  
  2061. ; Dodge Jump
  2062. ~v::Send, {Space}
  2063.  
  2064. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  2065. WiggleCamera()
  2066. {
  2067. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  2068. SetMouseDelay, 1
  2069.  
  2070. Send, {Click -15 0 0 Relative}
  2071. Send, {Click 15 0 0 Relative}
  2072. }
  2073.  
  2074. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  2075. LButtonAboutFace(functionKey)
  2076. {
  2077. Critical
  2078. MouseGetPos, initialCursorX, initialCursorY
  2079. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  2080.  
  2081. if (GetKeyState("LButton") and GetKeyState("RButton"))
  2082. Send, {%functionKey%}
  2083. else if (GetKeyState("LButton"))
  2084. {
  2085. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  2086. Send, {LButton up}
  2087. Sleep, 40
  2088. Send, {LButton down}
  2089.  
  2090. WiggleCamera()
  2091. Send, {%functionKey%}
  2092. }
  2093. else if (GetKeyState("RButton"))
  2094. {
  2095. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  2096. Send, {RButton up}
  2097. Send, {RButton down}
  2098.  
  2099. WiggleCamera()
  2100.  
  2101. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  2102. Send, {RButton up}
  2103.  
  2104. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2105. Click, %windowWidth% %windowY% Down
  2106. Send, {%functionKey%}
  2107. Click, Up
  2108. Send, {Click %initialCursorX% %initialCursorY% 0}
  2109.  
  2110. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  2111. if (GetKeyState("RButton", "P"))
  2112. {
  2113. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  2114. Sleep, 525
  2115.  
  2116. if (GetKeyState("RButton", "P"))
  2117. Send, {RButton down}
  2118. }
  2119. }
  2120. else
  2121. {
  2122. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2123. Click, %windowWidth% %windowY% Down
  2124. WiggleCamera()
  2125. Send, {%functionKey%}
  2126. Click, Up
  2127. Send, {Click %initialCursorX% %initialCursorY% 0}
  2128. }
  2129. }
  2130.  
  2131. F3::
  2132. F4::LButtonAboutFace("F3")
  2133.  
  2134. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  2135. 4::Send, {4}
  2136. RButton::Send, {RButton}
  2137. w::Send, {w}
  2138. a::Send, {a}
  2139. s::Send, {s}
  2140. d::Send, {d}
  2141.  
  2142. ; This fixes the bug where the character suddenly rotates in a random manner when the player goes on their mount while auto-run is active and the right mouse button is being pressed
  2143. ~'::
  2144. ; Toggled boolean variable that becomes true when mounting up
  2145. isMountUpAction := !isMountUpAction
  2146.  
  2147. ; This is for when the player actually mounts up and is physically pressing the right mouse button but not the left mouse button (aka the situation where the bug happens)
  2148. if (isMountUpAction and GetKeyState("RButton", "P") and !GetKeyState("LButton", "P"))
  2149. {
  2150. Critical
  2151.  
  2152. ; The best cursor placement to have when the mouse buttons are no longer pressed and the center of the screen also guarantees the code to work
  2153. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  2154. halfWindowWidth := windowWidth / 2
  2155. halfWindowHeight := windowHeight / 2
  2156.  
  2157. ; This is also necessary to make the original bugfix work and a high sleep time helps the user with regaining camera control automatically
  2158. Send, {RButton up}
  2159. Sleep, 100
  2160.  
  2161. ; Press both mouse buttons (prevents auto-run from being stopped accidentally later on and this also makes wiggling the camera possible)
  2162. Send, {Click %halfWindowWidth% %halfWindowHeight% Down}{RButton down}
  2163.  
  2164. ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user and holding both mouse buttons for atleast 50 milliseconds longer
  2165. WiggleCamera()
  2166. Sleep, 50
  2167.  
  2168. ; Executes code for physical mouse button state combinations (when both mouse buttons are physically pressed then it'll simply return without releasing them)
  2169. if (!GetKeyState("LButton", "P") and GetKeyState("RButton", "P"))
  2170. {
  2171. ; Release left mouse button and use auto-run instead
  2172. Send, {LButton up}
  2173. Send, {r}
  2174. }
  2175. else if (!GetKeyState("LButton", "P") and !GetKeyState("RButton", "P"))
  2176. ; Releases both mouse buttons
  2177. Send, {LButton up}{RButton up}
  2178. }
  2179.  
  2180. return
  2181.  
  2182. ; Left-click outside the chat area with an active chat input field and left-click inside an inactive chat input field both toggles the chat state of the macro as well
  2183. LButton::
  2184. Send, {LButton}
  2185. MouseGetPos, currentCursorX, currentCursorY
  2186.  
  2187. if (isChatActive)
  2188. {
  2189. if (currentCursorX > 490 or currentCursorY < 1147)
  2190. ToggleChatState()
  2191. }
  2192. else if (currentCursorX < 482 and currentCursorY > 1370)
  2193. ToggleChatState()
  2194.  
  2195. return
  2196.  
  2197.  
  2198. *********************************************************************************************************************************************************************************************
  2199. MODIFIED AT: 12/30/22 >> Guild Wars 2 - NEW 4.ahk:
  2200.  
  2201. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2202. ; #Warn ; Enable warnings to assist with detecting common errors.
  2203. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  2204. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  2205.  
  2206. ; Any attempt to launch this script when it's already running will reload it (the dialog box that normally appears in this situation gets skipped)
  2207. #SingleInstance Force
  2208.  
  2209. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  2210. #InstallMouseHook
  2211.  
  2212. global isChatActive := false
  2213.  
  2214. ; Terminates the macro if the game doesn't restart itself within 30 seconds. And also has recursive code, which restarts this method each time the game crashes and immediately restarts
  2215. ManageApp()
  2216. {
  2217. WinWait, Guild Wars 2,, 30
  2218.  
  2219. if (ErrorLevel == 1)
  2220. ExitApp
  2221. else
  2222. {
  2223. WinWaitClose
  2224. ManageApp()
  2225. }
  2226. }
  2227.  
  2228. ; Runs the game and terminates the macro when the game window doesn't exist any longer and wasn't being restarted either (keep this at the bottom of the auto-execute section)
  2229. RunWait, "C:\Program Files\Guild Wars 2\Gw2-64.exe"
  2230. ManageApp()
  2231.  
  2232. ; The code below only executes for the Guild Wars 2 window
  2233. #If (WinActive("Guild Wars 2"))
  2234.  
  2235. ToggleChatState()
  2236. {
  2237. Hotkey, If, (WinActive("Guild Wars 2"))
  2238. HotKey, v, Toggle
  2239. isChatActive := !isChatActive
  2240. }
  2241.  
  2242. ; Prevents hotkey interference when the chat is being used
  2243. ~Enter::ToggleChatState()
  2244.  
  2245. ; Dodge Jump
  2246. ~v::Send, {Space}
  2247.  
  2248. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  2249. WiggleCamera()
  2250. {
  2251. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  2252. SetMouseDelay, 1
  2253.  
  2254. Send, {Click -15 0 0 Relative}
  2255. Send, {Click 15 0 0 Relative}
  2256. }
  2257.  
  2258. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  2259. LButtonAboutFace(functionKey)
  2260. {
  2261. shouldUsePostponableHotkeys := true
  2262. Critical
  2263. MouseGetPos, initialCursorX, initialCursorY
  2264. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  2265.  
  2266. if (GetKeyState("LButton") and GetKeyState("RButton"))
  2267. Send, {%functionKey%}
  2268. else if (GetKeyState("LButton"))
  2269. {
  2270. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  2271. Send, {LButton up}
  2272. Sleep, 40
  2273. Send, {LButton down}
  2274.  
  2275. WiggleCamera()
  2276. Send, {%functionKey%}
  2277. }
  2278. else if (GetKeyState("RButton"))
  2279. {
  2280. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  2281. Send, {RButton up}
  2282. Send, {RButton down}
  2283.  
  2284. WiggleCamera()
  2285.  
  2286. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  2287. Send, {RButton up}
  2288.  
  2289. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2290. Click, %windowWidth% %windowY% Down
  2291. Send, {%functionKey%}
  2292. Click, Up
  2293. Send, {Click %initialCursorX% %initialCursorY% 0}
  2294.  
  2295. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  2296. if (GetKeyState("RButton", "P"))
  2297. {
  2298. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  2299. Sleep, 525
  2300.  
  2301. if (GetKeyState("RButton", "P"))
  2302. Send, {RButton down}
  2303. }
  2304. }
  2305. else
  2306. {
  2307. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2308. Click, %windowWidth% %windowY% Down
  2309. WiggleCamera()
  2310. Send, {%functionKey%}
  2311. Click, Up
  2312. Send, {Click %initialCursorX% %initialCursorY% 0}
  2313. }
  2314.  
  2315. shouldUsePostponableHotkeys := false
  2316. }
  2317.  
  2318. F3::
  2319. F4::LButtonAboutFace("F3")
  2320.  
  2321. ; This fixes the bug where the character suddenly rotates in a random manner when the player goes on their mount while auto-run is active and the right mouse button is being pressed
  2322. ~'::
  2323. ; Toggled boolean variable that becomes true when mounting up
  2324. isMountUpAction := !isMountUpAction
  2325.  
  2326. ; This is for when the player actually mounts up and is physically pressing the right mouse button but not the left mouse button (aka the situation where the bug happens)
  2327. if (isMountUpAction and GetKeyState("RButton", "P") and !GetKeyState("LButton", "P"))
  2328. {
  2329. shouldUsePostponableHotkeys := true
  2330. Critical
  2331.  
  2332. ; The best cursor placement to have when the mouse buttons are no longer pressed and the center of the screen also guarantees the code to work
  2333. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  2334. halfWindowWidth := windowWidth / 2
  2335. halfWindowHeight := windowHeight / 2
  2336.  
  2337. ; This is also necessary to make the original bugfix work and a high sleep time helps the user with regaining camera control automatically
  2338. Send, {RButton up}
  2339. Sleep, 100
  2340.  
  2341. ; Press both mouse buttons (prevents auto-run from being stopped accidentally later on and this also makes wiggling the camera possible)
  2342. Send, {Click %halfWindowWidth% %halfWindowHeight% Down}{RButton down}
  2343.  
  2344. ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user and holding both mouse buttons for atleast 50 milliseconds longer
  2345. WiggleCamera()
  2346. Sleep, 50
  2347.  
  2348. ; Executes code for physical mouse button state combinations (when both mouse buttons are physically pressed then it'll simply return without releasing them)
  2349. if (!GetKeyState("LButton", "P") and GetKeyState("RButton", "P"))
  2350. {
  2351. ; Release left mouse button and use auto-run instead
  2352. Send, {LButton up}
  2353. Send, {r}
  2354. }
  2355. else if (!GetKeyState("LButton", "P") and !GetKeyState("RButton", "P"))
  2356. ; Releases both mouse buttons
  2357. Send, {LButton up}{RButton up}
  2358.  
  2359. shouldUsePostponableHotkeys := false
  2360. }
  2361.  
  2362. return
  2363.  
  2364. ; Left-click outside the chat area with an active chat input field and left-click inside an inactive chat input field both toggles the chat state of the macro as well
  2365. OnLButton()
  2366. {
  2367. MouseGetPos, currentCursorX, currentCursorY
  2368.  
  2369. if (isChatActive)
  2370. {
  2371. if (currentCursorX > 490 or currentCursorY < 1147)
  2372. ToggleChatState()
  2373. }
  2374. else if (currentCursorX < 482 and currentCursorY > 1370)
  2375. ToggleChatState()
  2376. }
  2377.  
  2378. ; The hotkeys below can be made postponable but aren't by default so that they work faster whenever possible (set the shouldUsePostponableHotkeys boolean to false when you're done using it)
  2379. #If (WinActive("Guild Wars 2") and !shouldUsePostponableHotkeys)
  2380.  
  2381. ;~LButton::OnLButton()
  2382.  
  2383. ; This is necessary to test the keyboard mount-up hotkey (stops the GUI mount button from working, so that it won't interfere with my test results..)
  2384. LButton::
  2385. MouseGetPos, currentCursorX, currentCursorY
  2386. if (currentCursorX > 1678 and currentCursorX < 1728 and currentCursorY > 1349 and currentCursorY < 1398)
  2387. return
  2388.  
  2389. Send, {LButton down}
  2390. OnLButton()
  2391. return
  2392.  
  2393. LButton up::Send, {LButton up}
  2394.  
  2395. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  2396. ; The hotkeys below can be made postponable by setting the shouldUsePostponableHotkeys boolean to true
  2397. #If (WinActive("Guild Wars 2") and shouldUsePostponableHotkeys)
  2398.  
  2399. 4::Send, {4}
  2400.  
  2401. LButton::
  2402. Send, {LButton down}
  2403. OnLButton()
  2404. return
  2405.  
  2406. LButton up::Send, {LButton up}
  2407.  
  2408. RButton::Send, {RButton}
  2409. w::Send, {w}
  2410. a::Send, {a}
  2411. s::Send, {s}
  2412. d::Send, {d}
  2413.  
  2414.  
  2415. *********************************************************************************************************************************************************************************************
  2416. MODIFIED AT: 4/6/24 >> Guild Wars 2 - NEW 5.ahk:
  2417.  
  2418. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2419. ; #Warn ; Enable warnings to assist with detecting common errors.
  2420. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  2421. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  2422.  
  2423. ; Any attempt to launch this script when it's already running will reload it (the dialog box that normally appears in this situation gets skipped)
  2424. #SingleInstance Force
  2425.  
  2426. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  2427. #InstallMouseHook
  2428.  
  2429. global isChatActive := false
  2430.  
  2431. ; Terminates the macro if the game doesn't restart itself within 30 seconds. And also has recursive code, which restarts this method each time the game crashes and immediately restarts
  2432. ManageApp()
  2433. {
  2434. WinWait, Guild Wars 2,, 30
  2435.  
  2436. if (ErrorLevel == 1)
  2437. ExitApp
  2438. else
  2439. {
  2440. WinWaitClose
  2441. ManageApp()
  2442. }
  2443. }
  2444.  
  2445. ; Runs the game and terminates the macro when the game window doesn't exist any longer and wasn't being restarted either (keep this at the bottom of the auto-execute section)
  2446. RunWait, "C:\Program Files\Guild Wars 2\Gw2-64.exe"
  2447. ManageApp()
  2448.  
  2449. ; The code below only executes for the Guild Wars 2 window
  2450. #If (WinActive("Guild Wars 2"))
  2451.  
  2452. ToggleChatState()
  2453. {
  2454. Hotkey, If, (WinActive("Guild Wars 2"))
  2455. HotKey, v, Toggle
  2456. isChatActive := !isChatActive
  2457. }
  2458.  
  2459. ; Prevents hotkey interference when the chat is being used
  2460. ~Enter::ToggleChatState()
  2461.  
  2462. ; Dodge Jump
  2463. ~v::Send, {Space}
  2464.  
  2465. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  2466. WiggleCamera()
  2467. {
  2468. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  2469. SetMouseDelay, 1
  2470.  
  2471. Send, {Click -15 0 0 Relative}
  2472. Send, {Click 15 0 0 Relative}
  2473. }
  2474.  
  2475. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  2476. LButtonAboutFace(functionKey)
  2477. {
  2478. shouldUsePostponableHotkeys := true
  2479. Critical
  2480. MouseGetPos, initialCursorX, initialCursorY
  2481. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  2482.  
  2483. if (GetKeyState("LButton") and GetKeyState("RButton"))
  2484. Send, {%functionKey%}
  2485. else if (GetKeyState("LButton"))
  2486. {
  2487. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  2488. Send, {LButton up}
  2489. Sleep, 40
  2490. Send, {LButton down}
  2491.  
  2492. WiggleCamera()
  2493. Send, {%functionKey%}
  2494. }
  2495. else if (GetKeyState("RButton"))
  2496. {
  2497. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  2498. Send, {RButton up}
  2499. Send, {RButton down}
  2500.  
  2501. WiggleCamera()
  2502.  
  2503. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  2504. Send, {RButton up}
  2505.  
  2506. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2507. Click, %windowWidth% %windowY% Down
  2508. Send, {%functionKey%}
  2509. Click, Up
  2510. Send, {Click %initialCursorX% %initialCursorY% 0}
  2511.  
  2512. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  2513. if (GetKeyState("RButton", "P"))
  2514. {
  2515. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  2516. Sleep, 525
  2517.  
  2518. if (GetKeyState("RButton", "P"))
  2519. Send, {RButton down}
  2520. }
  2521. }
  2522. else
  2523. {
  2524. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2525. Click, %windowWidth% %windowY% Down
  2526. WiggleCamera()
  2527. Send, {%functionKey%}
  2528. Click, Up
  2529. Send, {Click %initialCursorX% %initialCursorY% 0}
  2530. }
  2531.  
  2532. shouldUsePostponableHotkeys := false
  2533. }
  2534.  
  2535. F3::
  2536. F4::LButtonAboutFace("F3")
  2537.  
  2538. ; Should probably make some code for left-clicking on the GUI mount-up button with the mouse manually (not using the mount-up key on the keyboard..), atleast if this works
  2539. ;'::
  2540. ;shouldUsePostponableHotkeys := true
  2541. ;Critical
  2542. ;SendEvent {Click 1700 1375}
  2543. ;SendEvent {Click 1700 1348 0}
  2544. ;WiggleCamera()
  2545. ;shouldUsePostponableHotkeys := false
  2546. ;return
  2547.  
  2548. ; If this code doesn't work, try the one above it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  2549. ; This might fix the bug where the character suddenly rotates in a random manner when the player goes on their mount
  2550. ; Copied from "Guild Wars 2 - NEW 2 (backup containing some more code that didn't rly seem necessary).ahk" and added the postponable hotkeys boolean & critical keyword)
  2551. '::
  2552. useMountUpCode := !useMountUpCode ; Toggled boolean variable that becomes true when mounting up
  2553.  
  2554. if (useMountUpCode)
  2555. {
  2556. shouldUsePostponableHotkeys := true
  2557. Critical
  2558.  
  2559. if (GetKeyState("LButton", "P") and GetKeyState("RButton", "P")) ; IF physically pressed down both mouse buttons
  2560. {
  2561. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  2562. Send, {'} ; Mount up while the mouse buttons are still pressed in
  2563. return
  2564. }
  2565. else if (GetKeyState("RButton", "P")) ; IF physically pressed down right mouse button
  2566. {
  2567. Send, {LButton up}{RButton up} ; Removes glitchy auto-run behaviour where it suddenly stops
  2568. Sleep, 25 ; Removes glitchy auto-run behaviour where it suddenly stops
  2569. Send, {LButton down}{RButton down} ; Press both mouse buttons (prevents stopping active auto-run permanently below by stopping it temporarily)
  2570.  
  2571. WiggleCamera() ; Wiggling camera to make mouse movement work when the mouse gets controlled by the user
  2572. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  2573.  
  2574. if (GetKeyState("LButton", "P") and GetKeyState("RButton", "P")) ; IF physically pressed down both mouse buttons
  2575. Send, {'} ; Mount up while the mouse buttons are still pressed in
  2576. else
  2577. { ; ELSE executing code of this scope
  2578. Send, {'} ; Mount up while the mouse buttons are still pressed in
  2579. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  2580. Send, {LButton up} ; Release left mouse button
  2581. Send, {r} ; Use auto-run instead
  2582. }
  2583.  
  2584. return
  2585. }
  2586. else ; ELSE
  2587. {
  2588. Send, {LButton down}{RButton down} ; Press both mouse buttons
  2589. WiggleCamera() ; Wiggling camera to make mouse control work when done by the user
  2590. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  2591. Send, {'} ; Mount up while the mouse buttons are still pressed in
  2592. Sleep, 50 ; Hold both mouse buttons for 50 milliseconds
  2593.  
  2594. if (GetKeyState("LButton", "P") and GetKeyState("RButton", "P")) ; IF physically pressed down both mouse buttons
  2595. return ; Keep holding both mouse buttons
  2596. else ; ELSE
  2597. Send, {LButton up}{RButton up} ; Release both mouse buttons
  2598. }
  2599.  
  2600. shouldUsePostponableHotkeys := false
  2601. }
  2602. else
  2603. Send, {'} ; Use default behaviour when mounting down
  2604.  
  2605. return
  2606.  
  2607. ; Left-click outside the chat area with an active chat input field and left-click inside an inactive chat input field both toggles the chat state of the macro as well
  2608. OnLButton()
  2609. {
  2610. MouseGetPos, currentCursorX, currentCursorY
  2611.  
  2612. if (isChatActive)
  2613. {
  2614. if (currentCursorX > 490 or currentCursorY < 1147)
  2615. ToggleChatState()
  2616. }
  2617. else if (currentCursorX < 482 and currentCursorY > 1370)
  2618. ToggleChatState()
  2619. }
  2620.  
  2621. ; The hotkeys below can be made postponable but aren't by default so that they work faster whenever possible (set the shouldUsePostponableHotkeys boolean to false when you're done using it)
  2622. #If (WinActive("Guild Wars 2") and !shouldUsePostponableHotkeys)
  2623.  
  2624. ;~LButton::OnLButton()
  2625.  
  2626. ; This is necessary to test the keyboard mount-up hotkey (stops the GUI mount button from working, so that it won't interfere with my test results..)
  2627. LButton::
  2628. MouseGetPos, currentCursorX, currentCursorY
  2629. if (currentCursorX > 1678 and currentCursorX < 1728 and currentCursorY > 1349 and currentCursorY < 1398)
  2630. return
  2631.  
  2632. Send, {LButton down}
  2633. OnLButton()
  2634. return
  2635.  
  2636. LButton up::Send, {LButton up}
  2637.  
  2638. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  2639. ; The hotkeys below can be made postponable by setting the shouldUsePostponableHotkeys boolean to true
  2640. #If (WinActive("Guild Wars 2") and shouldUsePostponableHotkeys)
  2641.  
  2642. 4::Send, {4}
  2643.  
  2644. LButton::
  2645. Send, {LButton down}
  2646. OnLButton()
  2647. return
  2648.  
  2649. LButton up::Send, {LButton up}
  2650.  
  2651. RButton::Send, {RButton}
  2652. w::Send, {w}
  2653. a::Send, {a}
  2654. s::Send, {s}
  2655. d::Send, {d}
  2656.  
  2657.  
  2658. *********************************************************************************************************************************************************************************************
  2659. MODIFIED AT: 9/16/22 >> Guild Wars 2 - NEW.ahk:
  2660.  
  2661. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2662. ; #Warn ; Enable warnings to assist with detecting common errors.
  2663. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  2664. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  2665.  
  2666. ; Any attempt to launch this script when it's already running will be ignored (skips the dialog box and leaves the old instance running)
  2667. #SingleInstance Ignore
  2668.  
  2669. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  2670. #InstallMouseHook
  2671.  
  2672. ; The code below only executes for the Guild Wars 2 window
  2673. #IfWinActive Guild Wars 2
  2674.  
  2675. isGameChatActive := false
  2676.  
  2677. ; These hotkeys aren't needed straight away and can be turned on when any of these hotkeys actually need to be used
  2678. ;HotKey, LButton, Off
  2679. HotKey, RButton, Off
  2680.  
  2681. ToggleHotkeys()
  2682. {
  2683. HotKey, v, Toggle
  2684. HotKey, F3, Toggle
  2685. HotKey, F4, Toggle
  2686. ;HotKey, LButton, Toggle
  2687. }
  2688.  
  2689. ; Suspends hotkeys when making the input field of the chat active with the Enter key (and it will unsuspend the hotkeys when Enter is pressed again)
  2690. Enter::
  2691. ToggleHotkeys()
  2692. Send, {Enter}
  2693. isGameChatActive := !isGameChatActive
  2694. return
  2695.  
  2696. ; Dodge Jump
  2697. ~v::Send, {Space}
  2698.  
  2699. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  2700. WiggleCamera()
  2701. {
  2702. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  2703. SetMouseDelay, 1
  2704.  
  2705. SendEvent {Click -15 0 0 Relative}
  2706. SendEvent {Click 15 0 0 Relative}
  2707. }
  2708.  
  2709. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  2710. LButtonAboutFace(functionKey)
  2711. {
  2712. Critical
  2713. MouseGetPos, initialCursorX, initialCursorY
  2714. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  2715.  
  2716. if (GetKeyState("LButton") and GetKeyState("RButton"))
  2717. Send, {%functionKey%}
  2718. else if (GetKeyState("LButton"))
  2719. {
  2720. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  2721. Send, {LButton up}
  2722. Sleep, 40
  2723. Send, {LButton down}
  2724.  
  2725. WiggleCamera()
  2726. Send, {%functionKey%}
  2727. }
  2728. else if (GetKeyState("RButton"))
  2729. {
  2730. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  2731. Send, {RButton up}
  2732. Send, {RButton down}
  2733.  
  2734. WiggleCamera()
  2735.  
  2736. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  2737. Send, {RButton up}
  2738. HotKey, RButton, On
  2739.  
  2740. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2741. Click, %windowWidth% %windowY% Down
  2742. Send, {%functionKey%}
  2743. Click, Up
  2744. SendEvent {Click %initialCursorX% %initialCursorY% 0}
  2745.  
  2746. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  2747. if (GetKeyState("RButton", "P"))
  2748. {
  2749. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  2750. Sleep, 525
  2751.  
  2752. if (GetKeyState("RButton", "P"))
  2753. Send, {RButton down}
  2754. }
  2755.  
  2756. HotKey, RButton, Off
  2757. }
  2758. else
  2759. {
  2760. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2761. HotKey, RButton, On
  2762. Click, %windowWidth% %windowY% Down
  2763. WiggleCamera()
  2764. Send, {%functionKey%}
  2765. Click, Up
  2766. SendEvent {Click %initialCursorX% %initialCursorY% 0}
  2767. HotKey, RButton, Off
  2768. }
  2769. }
  2770. F3::
  2771. F4::LButtonAboutFace("F3")
  2772.  
  2773. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  2774. 4::Send, {4}
  2775.  
  2776. ; Or maybe I should use the Wiggle method instead if this one doesn't work and if it does work then I can also try button presses without holding them down a for 50 milliseconds
  2777. StabilizeScreen()
  2778. {
  2779. Send, {LButton down}{RButton down} ; Press both
  2780. Sleep, 50 ; Hold both for 50 milliseconds
  2781. Send, {LButton up}{RButton up} ; Release both
  2782. }
  2783.  
  2784. ; Simply calling StabilizeScreenAndRun() causes buggy run/stop behaviour. So I'm just clicking on the game button instead, to mount-up and then it returns the cursor to its initial position
  2785. '::
  2786. MouseGetPos, initialCursorX, initialCursorY
  2787. SendEvent {Click 1700 1375}
  2788. SendEvent {Click %initialCursorX% %initialCursorY% 0}
  2789. return
  2790.  
  2791. ; Left-click outside the chat area (when this hotkey gets enabled, is off by default) will unsuspend the disabled hotkeys as well, because they only need to stay disabled while chatting
  2792. ~LButton::
  2793. if (isGameChatActive)
  2794. {
  2795. MouseGetPos, currentCursorX, currentCursorY
  2796. if (currentCursorX > 490 or currentCursorY < 1147)
  2797. ToggleHotkeys()
  2798. }
  2799. else
  2800. {
  2801. MouseGetPos, currentCursorX, currentCursorY
  2802. if (currentCursorX > 1678 and currentCursorX < 1728 and currentCursorY > 1349 and currentCursorY < 1398)
  2803. StabilizeScreen()
  2804. }
  2805. return
  2806.  
  2807. ; The right mouse button can be manually disabled by turning this hotkey on
  2808. RButton::return
  2809.  
  2810.  
  2811. *********************************************************************************************************************************************************************************************
  2812. MODIFIED AT: 2/19/22 >> Guild Wars 2 - Postpone all input (experiment to avoid hardcoding teleport AND movement hotkeys).ahk:
  2813.  
  2814. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2815. ; #Warn ; Enable warnings to assist with detecting common errors.
  2816. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  2817. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  2818.  
  2819. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  2820. #InstallMouseHook
  2821.  
  2822. ; The code below only executes for the Guild Wars 2 window
  2823. #IfWinActive Guild Wars 2
  2824.  
  2825. ; These hotkeys aren't needed straight away and can be turned on when any of these hotkeys actually need to be used
  2826. HotKey, LButton, Off
  2827. HotKey, RButton, Off
  2828. ;HotKey, 4, Off
  2829.  
  2830. ToggleHotkeys()
  2831. {
  2832. HotKey, v, Toggle
  2833. HotKey, F3, Toggle
  2834. HotKey, F4, Toggle
  2835. HotKey, LButton, Toggle
  2836. }
  2837.  
  2838. ; Suspends hotkeys when making the input field of the chat active with the Enter key (and it will unsuspend the hotkeys when Enter is pressed again)
  2839. Enter::
  2840. ToggleHotkeys()
  2841. Send, {Enter}
  2842. return
  2843.  
  2844. ; Dodge Jump
  2845. ~v::Send, {Space}
  2846.  
  2847. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  2848. WiggleCamera()
  2849. {
  2850. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  2851. SetMouseDelay, 1
  2852.  
  2853. SendEvent {Click -15 0 0 Relative}
  2854. SendEvent {Click 15 0 0 Relative}
  2855. }
  2856.  
  2857. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  2858. LButtonAboutFace(functionKey)
  2859. {
  2860. MouseGetPos, initialCursorX, initialCursorY
  2861. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  2862.  
  2863. if (GetKeyState("LButton") and GetKeyState("RButton"))
  2864. Send, {%functionKey%}
  2865. else if (GetKeyState("LButton"))
  2866. {
  2867. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  2868. Send, {LButton up}
  2869. Sleep, 40
  2870. Send, {LButton down}
  2871.  
  2872. WiggleCamera()
  2873. Send, {%functionKey%}
  2874. }
  2875. else if (GetKeyState("RButton"))
  2876. {
  2877. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  2878. Send, {RButton up}
  2879. Send, {RButton down}
  2880.  
  2881. WiggleCamera()
  2882.  
  2883. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  2884. Send, {RButton up}
  2885. HotKey, RButton, On
  2886.  
  2887. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2888. Click, %windowWidth% %windowY% Down
  2889. Send, {%functionKey%}
  2890. Click, Up
  2891. SendEvent {Click %initialCursorX%, %initialCursorY% 0}
  2892.  
  2893. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  2894. if (GetKeyState("RButton", "P"))
  2895. {
  2896. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  2897. Sleep, 525
  2898.  
  2899. if (GetKeyState("RButton", "P"))
  2900. Send, {RButton down}
  2901. }
  2902.  
  2903. HotKey, RButton, Off
  2904. }
  2905. else
  2906. {
  2907. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  2908. HotKey, RButton, On
  2909. Click, %windowWidth% %windowY% Down
  2910. WiggleCamera()
  2911. Send, {%functionKey%}
  2912. Click, Up
  2913. SendEvent {Click %initialCursorX%, %initialCursorY% 0}
  2914. HotKey, RButton, Off
  2915. }
  2916. }
  2917. F3::
  2918. F4::
  2919. ;HotKey, 4, On
  2920. ;BlockInput, On
  2921. ;Input, SingleKey, L1
  2922. ;SetTimer, CatchInput, -100
  2923. Critical
  2924. Sleep, 2000
  2925. LButtonAboutFace("F3")
  2926. ;BlockInput, Off
  2927. ;HotKey, 4, Off
  2928. if (useTeleport)
  2929. {
  2930. Send, {4}
  2931. useTeleport := False
  2932. }
  2933. return
  2934.  
  2935. CatchInput: ; Maybe there is a better word than 'catch' ??
  2936. Input, SingleKey, L1
  2937. return
  2938.  
  2939. 4::Send, {4}
  2940. ; This lets the player teleport as soon as it becomes possible (when this hotkey gets enabled, is off by default)
  2941. ;4::useTeleport := True
  2942.  
  2943. ; Left-click outside the chat area (when this hotkey gets enabled, is off by default) will unsuspend the disabled hotkeys as well, because they only need to stay disabled while chatting
  2944. ~LButton::
  2945. MouseGetPos, currentCursorX, currentCursorY
  2946. if (currentCursorX > 490 or currentCursorY < 1147)
  2947. ToggleHotkeys()
  2948. return
  2949.  
  2950. ; The right mouse button can be manually disabled by turning this hotkey on
  2951. RButton::return
  2952.  
  2953.  
  2954. *********************************************************************************************************************************************************************************************
  2955. MODIFIED AT: 1/19/24 >> Guild Wars 2.ahk:
  2956.  
  2957. #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
  2958. ; #Warn ; Enable warnings to assist with detecting common errors.
  2959. SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
  2960. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
  2961.  
  2962. ; Any attempt to launch this script when it's already running will be ignored (skips the dialog box and leaves the old instance running)
  2963. #SingleInstance Ignore
  2964.  
  2965. ; This allows the physical mouse key states to be read, like for example GetKeyState("RButton", "P")
  2966. #InstallMouseHook
  2967.  
  2968. ; The code below only executes for the Guild Wars 2 window
  2969. #IfWinActive Guild Wars 2
  2970.  
  2971. ; These hotkeys aren't needed straight away and can be turned on when any of these hotkeys actually need to be used
  2972. HotKey, LButton, Off
  2973. HotKey, RButton, Off
  2974.  
  2975. ToggleHotkeys()
  2976. {
  2977. HotKey, v, Toggle
  2978. HotKey, F3, Toggle
  2979. HotKey, F4, Toggle
  2980. HotKey, LButton, Toggle
  2981. }
  2982.  
  2983. ; To hide the OSD
  2984. Volume_Up:: SoundSet +2
  2985. Volume_Down::SoundSet -2
  2986.  
  2987. ; Suspends hotkeys when making the input field of the chat active with the Enter key (and it will unsuspend the hotkeys when Enter is pressed again)
  2988. Enter::
  2989. ToggleHotkeys()
  2990. Send, {Enter}
  2991. return
  2992.  
  2993. ; Dodge Jump
  2994. ~v::Send, {Space}
  2995.  
  2996. ; The About Face feature is only guaranteed to work if the camera has rotated since the last time the player had moved (so this rotates it a bit and then back again)
  2997. WiggleCamera()
  2998. {
  2999. ; Using the lowest possible mouse delay for a wiggle that's barely noticeable (going even lower will make the wiggle stop working)
  3000. SetMouseDelay, 1
  3001.  
  3002. SendEvent {Click -15 0 0 Relative}
  3003. SendEvent {Click 15 0 0 Relative}
  3004. }
  3005.  
  3006. ; Uses the About Face feature without turning the camera along with it (requires the keybind that's used in guild wars 2)
  3007. LButtonAboutFace(functionKey)
  3008. {
  3009. Critical
  3010. MouseGetPos, initialCursorX, initialCursorY
  3011. WinGetActiveStats, windowTitle, windowWidth, windowHeight, windowX, windowY
  3012.  
  3013. if (GetKeyState("LButton") and GetKeyState("RButton"))
  3014. Send, {%functionKey%}
  3015. else if (GetKeyState("LButton"))
  3016. {
  3017. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the left mouse button was held pressed down (before this method got called)
  3018. Send, {LButton up}
  3019. Sleep, 40
  3020. Send, {LButton down}
  3021.  
  3022. WiggleCamera()
  3023. Send, {%functionKey%}
  3024. }
  3025. else if (GetKeyState("RButton"))
  3026. {
  3027. ; Removes glitchy camera behaviour that would otherwise have happened if the cursor had been moved while the right mouse button was held pressed down (before this method got called)
  3028. Send, {RButton up}
  3029. Send, {RButton down}
  3030.  
  3031. WiggleCamera()
  3032.  
  3033. ; Preventing the camera from both accidentally turning 180 degrees and stopping any movement
  3034. Send, {RButton up}
  3035. HotKey, RButton, On
  3036.  
  3037. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  3038. Click, %windowWidth% %windowY% Down
  3039. Send, {%functionKey%}
  3040. Click, Up
  3041. SendEvent {Click %initialCursorX% %initialCursorY% 0}
  3042.  
  3043. ; Make the right mouse button become pressed down again as long as it's still physically pressed down, but only as soon as it stops leading to unwanted behaviour
  3044. if (GetKeyState("RButton", "P"))
  3045. {
  3046. ; Delay the upcoming action to prevent the camera from turning 180 degrees and then the right mouse button will also stay pressed down
  3047. Sleep, 525
  3048.  
  3049. if (GetKeyState("RButton", "P"))
  3050. Send, {RButton down}
  3051. }
  3052.  
  3053. HotKey, RButton, Off
  3054. }
  3055. else
  3056. {
  3057. ; Holds the LButton pressed down (in top-right corner) while it sends the specified function key
  3058. HotKey, RButton, On
  3059. Click, %windowWidth% %windowY% Down
  3060. WiggleCamera()
  3061. Send, {%functionKey%}
  3062. Click, Up
  3063. SendEvent {Click %initialCursorX% %initialCursorY% 0}
  3064. HotKey, RButton, Off
  3065. }
  3066. }
  3067. F3::
  3068. F4::LButtonAboutFace("F3")
  3069.  
  3070. ; This is where all the hotkeys should be that can be postponed (like when trying to use a teleport skill when LButtonAboutFace is being executed, which is an uninterruptible function..)
  3071. 4::Send, {4}
  3072.  
  3073. ; Left-click outside the chat area (when this hotkey gets enabled, is off by default) will unsuspend the disabled hotkeys as well, because they only need to stay disabled while chatting
  3074. ~LButton::
  3075. MouseGetPos, currentCursorX, currentCursorY
  3076. if (currentCursorX > 490 or currentCursorY < 1147)
  3077. ToggleHotkeys()
  3078. return
  3079.  
  3080. ; The right mouse button can be manually disabled by turning this hotkey on
  3081. RButton::return
  3082.  
  3083.  
  3084. *********************************************************************************************************************************************************************************************
  3085. MODIFIED AT: 7/29/24 >> README.txt:
  3086.  
  3087. it might be that I need to programmatically use temporarily only auto-run and RMB instead of both LMB and RMB when both are physically pressed and the ' hotkey gets used
  3088. not sure, seemed like the issue only happens when both were physically pressed and the ' hotkey got used.. but the issue wasn't very disturbing, so maybe it gets fixed partially, dunno
  3089. hard to tell what exactly happened, if it was really the warclaw mount-up issue or not
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement