1
votes

I've written an autohotkey for Path of Exile (a game I'm playing) to press 5 buttons at once when I press single key (my spacebar). Currently, when I press the space bar, autohotkey also presses q, e, w, Space, and Z. (all 5)

However, when I'm chatting and press Spacebar, I get "qew z" entered into my chat. This is super annoying, so I created a fix: "Toggle the autohotkey script off when I press the Enter key on my keyboard and then toggle it back on when I press Enter again." (most games use the enter key to begin chatting) This worked, but after some time my script would become out of sync with the game. It would be on when I am chatting, disrupting my chat, and then turn off when I'm done chatting.

I discovered that this problem was sometimes a result of me pressing my shift or control and Enter at the same time. This opens chat, but doesn't pause the script. To fix this, I added a ^ and + in front of my enter scripts, but it still is finding ways to get out of sync!!!!

Note: #Ifwinactive, Path of Exile is at the top to prevent this script from triggering when I don't have path of exile open. That works perfectly (I think).

Please check my code below. I have two questions:

  1. What is causing my script to get out of sync with the chat in the game?

  2. What is the best fix for my issue so that the script does not run when I have chat open, and always runs again when I'm finished chatting?

Thanks in advance!

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Recommended for catching common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#Ifwinactive, Path of Exile

Space::
Send {q}
Send {e}
Send {w}
Send {Space}
Send {z}
Return

^Space::
Send {q}
Send {e}
Send {w}
Send {Space}
Send {z}
Return

~Enter:: 
 Suspend Permit
 Suspend
 Return

~!Enter:: 
 Suspend Permit
 Suspend
 Return

~^Enter:: 
 Suspend Permit
 Suspend
 Return

~+Enter::
 Suspend Permit
 Suspend
 Return
1
Not necessarily what you want, but as you may have found out, there are many ways to break your script. E.g. if the game lags and you hit enter twice, but only one hit is registered; probably, you can leave the chat with Esc or some other key, so AHK won't know it should be active again; etc. You might want to switch to a more reliable solution. Here are some suggestions: 1) Create a unique hotkey (like ^Space or maybe a quick "double space") for either the normal space or your special functionality. 2) Define "reactivation" hotkey that always unsuspends the script when it's out of sync.MCL
I'll definitely watch for the escape key or double presses. Never thought of that :)Alan Nelson

1 Answers

2
votes

Wildcard * asterisk is what you wanted. It works by allowing the hotkey to trigger even if any combination of keys being held down. No need to repeat code, a blank hotkey above another will trigger the one below. Again, no reason to have all those keys typed out like you did. Having them laid out inline works and is tidy.

Try:

SendMode Input 

#Ifwinactive, Path of Exile

^Space::
$Space::Send, qew{Space}z

*~Enter::Suspend