Script will not work if not running twice

Ask gaming related questions (AHK v1.1 and older)
rfxcasey
Posts: 8
Joined: 17 Jul 2020, 11:38

Script will not work if not running twice

Post by rfxcasey » 25 Jan 2022, 14:41

I'm using a hotkey activated macro script to automate procedures in a program. If I only run one instance of the script, it does not work, if I run the same script under two different names simultaneously it works perfectly. Trying to figure out why.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Script will not work if not running twice

Post by BoBo » 25 Jan 2022, 14:45

Hard to guess what's the problem without seeing those scripts :think:

rfxcasey
Posts: 8
Joined: 17 Jul 2020, 11:38

Re: Script will not work if not running twice

Post by rfxcasey » 25 Jan 2022, 17:23

BoBo wrote:
25 Jan 2022, 14:45
Hard to guess what's the problem without seeing those scripts :think:

Code: Select all

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <[email protected]>
;
; Script Function:
;	Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

;~ if not A_IsAdmin
;~ {
   ;~ Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ;~ ExitApp
;~ }

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance,Force ;Only launch 1 instance of thise script.
#Persistent ;Will keep it running...

;;;;;;;;;;;;Hotkeys to help develop your code;;;;;;;;;;;;;;
^r::Reload ;This will reload this script
^e::Edit ;This will edit this script

;;;;;;;;;;;;Hotkeys:::::::::: Alt key is !	Windows key is #,	Shift key is +,	Control key is ^

+q:: ;Hotkey to trigger the keystrokes
Sleep, 1000
;Set Sparrow
SendInput +{d}
Sleep, 1000
SendInput {1}
Sleep, 1000
SendInput {1}
Sleep, 1000
SendInput {2}
Sleep, 1000
SendInput {2}
Sleep, 1000
SendInput {LCtrl down}{7}{LCtrl up}
Sleep, 1000
SendInput {LCtrl down}{7}{LCtrl up}
Sleep, 1000
SendInput {LCtrl down}{7}{LCtrl up}
Sleep, 1000
SendInput {LAlt down}{8}{LAlt up}
;Set AMRAAM
Sleep, 1000
SendInput +{w}
Sleep, 1000
SendInput {1}
Sleep, 1000
SendInput {1}
Sleep, 1000
SendInput {2}
Sleep, 1000
SendInput {1}
Sleep, 1000
SendInput {6}
Sleep, 1000
SendInput {LAlt down}{6}{LAlt up}
Sleep, 1000
SendInput {LCtrl down}{7}{LCtrl up}
Sleep, 1000
SendInput {LCtrl down}{7}{LCtrl up}
Sleep, 1000
SendInput {LCtrl down}{7}{LCtrl up}
Sleep, 1000
SendInput {LAlt down}{8}{LAlt up}
;Set Sidewinder
Sleep, 1000
SendInput +{s}
Sleep, 1000
SendInput {LAlt down}{7}{LAlt up}
Sleep, 1000
SendInput {LCtrl down}{7}{LCtrl up}
Sleep, 1000
SendInput {LCtrl down}{7}{LCtrl up}
Sleep, 1000
SendInput {LCtrl down}{7}{LCtrl up}
Sleep, 1000
SendInput {LAlt down}{8}{LAlt up}
Sleep, 1000
SendInput +{d}
Sleep, 1000
SendInput +{s}
Sleep, 1000
SendInput +{w}
;~ ;return ; Finishes the script action
[Mod edit: [code][/code] tags added.]

rfxcasey
Posts: 8
Joined: 17 Jul 2020, 11:38

Re: Script will not work if not running twice

Post by rfxcasey » 26 Jan 2022, 10:45

So nothing? Can someone at least tell me what format or mechanism is used to send the hotkey command to Autohotkey and can it be changed?

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Script will not work if not running twice

Post by amateur+ » 26 Jan 2022, 11:04

For me your script works fine if I press +q. Without multiple scripts being running. So I don't know how to help you.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Script will not work if not running twice

Post by boiler » 26 Jan 2022, 11:11

I suggest trying simpler scripts with one or two hotkeys tied to a simple action, then slowly build it out to your full script until you see what addition causes it to fail as a single script.

rfxcasey
Posts: 8
Joined: 17 Jul 2020, 11:38

Re: Script will not work if not running twice

Post by rfxcasey » 27 Jan 2022, 01:39

amateur+ wrote:
26 Jan 2022, 11:04
For me your script works fine if I press +q. Without multiple scripts being running. So I don't know how to help you.
Yeah, it's not really the script per say, it's getting the script macro to trigger. The running script isn't getting the hotkey input when in game unless I run two scripts. Could be a DirectX directinput issue but figured someone here might know more about it. What method or protocol is the hotkey sent to the script to activate the macro and can that protocol be changed to something else. You can send keystrokes from the script via different methods can you do the same for the hotkey that activates it?

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Script will not work if not running twice

Post by amateur+ » 27 Jan 2022, 08:43

Ususally @mikeyww sends users to read this topic at first.
How to Make AHK Work in Most Games - The Basics - AutoHotkey Community
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Post Reply

Return to “Gaming Help (v1)”