Suppress sending modifier key to game & breaking loop from outside of #IfWinActive condition

Ask gaming related questions
Kaeptn
Posts: 4
Joined: 20 Jun 2020, 23:03

Suppress sending modifier key to game & breaking loop from outside of #IfWinActive condition

21 Jun 2020, 13:14

Hey there!
I am trying to create a script for a game to put stuff in the stash by triggering a loop of control leftclicking
when I press ALT rightclick.
The problem is that the game itself has a binding to link the item in chat when you press CTRL ALT Leftclick.
So while the sript works fine, it will ocasionally spam putting the item names in the chat.
Hence the attemt to solve that issue by adding {blind}{Alt Up} infront of the send command to simulate ALT being not pressed down for the game, to avoid triggering the full shortcut combination to post in chat.

Another problem is that if I ALT TAB out of the game while I am triggerin the loop, the loop will still be running and will mess with other programs on my second monitor. So I need to find a way of suspending the loop when I am not focused on the game window. The problem here is that the break condition for the loop sits in the #IfWinActive portion for the game. So at the very moment when I am ALT TABbing out of the game, the break will not be callable by the script anymore since the game is not focussed.

Simplified version of my script:

Code: Select all

#IfWinActive ahk_exe YourGame.exe
{
	!RButton::
			Loop
			{
				AutoCtrlClicks()
				Sleep, 100
			GetKeyState, state, RButton, p
				if state = U
				{
					break
					Send {Lbutton up} 
					Send {Ctrl up}
				}		
			}
	return
	
		AutoCtrlClicks()				; AutoCtrlClick Function
		{
			BlockInput On 
				Send {blind}{Alt Up}{Ctrl down}{Lbutton down}{Lbutton up}{Ctrl up}
			BlockInput Off
		}
}
#IfWinActive
Help very much apprechiated!

Greets!
Kaeptn
Posts: 4
Joined: 20 Jun 2020, 23:03

Re: Suppress sending modifier key to game & breaking loop from outside of #IfWinActive condition

01 Jul 2020, 14:53

So I just did a workaround of including alot of "Send {LAlt Up}" in the script so the keybinging for linking in chat would not be triggered anymore.
But furthermore, eventhough I replaced the loop with a while funciton: the modifier keys will eventually get stuck in a loop, only breaking when I mash the keys in the binding a bit.
I researched the problem of while functions getting stuck in a loop and modifier key that will get stuck. but on none of these threads were working solutions.

Code right now is as follows:

Code: Select all

#IfWinActive ahk_exe YourGame.exe
{
			$!RButton::
			while GetKeyState("LAlt")
					{
						Send {LAlt Up}
						AutoCtrlClicks()
						Send {LAlt Up}
						Sleep, 50
						Send {LAlt Up}
					}
			return
			
				AutoCtrlClicks()				; AutoCtrlClick Function
				{
					BlockInput On 
						Send, {LAlt Up}{Ctrl down}{LAlt Up}{Lbutton down}{LAlt Up}{Lbutton up}{LAlt Up}{Ctrl up}{LAlt Up}
					BlockInput Off
				}
					
			$+!RButton::
			while GetKeyState("LAlt")
				{
					AutoLeftClicks()
					Sleep, 50
				}
			return
			
				AutoLeftClicks()				; AutoLeftClick Function
				{
					BlockInput On 
						Send, {Lbutton down}{Lbutton up}
					BlockInput Off
				}		
}
#IfWinActive

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 21 guests