简体   繁体   中英

How do I turn off an autohotkey script when I press enter to chat in games?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM