Voilà un code qui - je crois - tient compte et module tout les paramètres pouvant éventuellement faire échouer la commande - ControlSend, nommément - où, à l'inverse, la faire réussir - c'est-à-dire: le paramètre control de la commande en question; les privilèges d'administrateur accordés au script (en particulier si ton jeu les possède cependant que ton script non); le sendmode. Si, une fois le MsgBox apparu, aucune des actions liées aux keys envoyées (dans l'exemple s down - s up) n'a produit l'effet escompté dans le jeu, alors tu ne pourras vraisemblablement pas "jouer" à ton jeu de cette manière...
Code: Select all
target := "C:\Windows\System32\notepad.exe" ; teste avec notepad et remplace le chemin du fichier par le full path de ton executable ensuite
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {
try {
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
} ExitApp
} ; https://www.autohotkey.com/docs/commands/Run.htm#RunAs
run, % target,,, PID
WinWait, ahk_pid %PID%
AHKID := "ahk_id " . WinExist()
WinMinimize
for index, inputMode in StrSplit("Input|Play|Event|InputThenPlay", "|") {
SendMode % inputMode
ControlSend,, {s down}
Sleep, 200
ControlSend,, {s up}
sleep, 400
ControlSend, ahk_parent, {s down}
Sleep, 200
ControlSend, ahk_parent, {s up}
sleep, 400
}
MsgBox