Script pour application en background Topic is solved

Poser vos questions de programmation en AutoHotkey
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Script pour application en background  Topic is solved

15 Dec 2017, 14:36

Salut,

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
my scripts
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

15 Dec 2017, 15:12

Alors j'ai essayé ta commande , avec le notepad ça marche niquel. Par contre quand j'utilise le chemin complet du jeu, le jeu se refresh (écran de chargement de 1 ou 2 secondes) puis se remet normal, mais les touches ne s'appliquent pas a la fe,être, comme si elle avaient perdu le focus (c'est à dire que, ça fait le son windows de comme quand tu appuie une touche dans le vide, 4 fois, ce qui implique que les touches perdent le focus de l'application? je ne sais pas)

edit : tésté avec le jeu en mode fenêtré
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

15 Dec 2017, 15:17

Je rectifie : Si le jeu est déjà ouvert, il demandera d'ouvrir un nouveau client, et les touches partent dans le vide.

Si aucun client de jeu n'es ouvert, le script se lance mais aucune application ne s'ouvre

Je précise que l'application se lance via un launcher aussi,je pensais donc plus simple d'avoir l'application déjà ouverte pour juste send des keystrokes
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

15 Dec 2017, 18:33

C'est bizarre, j'ai tenté avec une commande très simple, CTRL+J pour activer, pas de control send, juste activer sur la fenêtre en focus et toujours rien ne se passe

Code: Select all

#NoEnv
SetWorkingDir %A_ScriptDir%
SendMode InputThenPlay


^j::
F10::ExitApp
Loop
{


Send, , {Alt down}
Sleep, 90
Send, , {2 down}
Sleep, 160
Send, , {2 up}
Sleep, 40
Send, , {Alt up}
Sleep, 1000
Send, , {1 down}
Sleep 15500
Send, , {1 up}
Sleep 1000
Send, , {F down}
Sleep, 170
Send, , {F up}
Sleep 100
Send, , {4 down}
Sleep 200
Send, , {4 up}
Sleep 3500
Send, , {S down}
Sleep 10
Send, , {S up}

}
Return
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Script pour application en background

15 Dec 2017, 19:56

J'ai vu un certain temps que SetKeyDelay peut jouer quand il s'agit de jeux. Si ton jeu ne répond pas au s envoyé je crains de ne pas avoir d'autre solution à te proposer... En même temps, pour ma part, ce genre de commandes c'est pas trop mon truc même si je sais que c'est aussi cela qui fait la renommée de AHK, en particulier auprès de gamers... Abstraction faite de nouvelles éventuelles solutions apportées, je te conseillerais pour ma part de te rapporter à la partie anglophone dédiée au gaming si le cas échéant le script ci-dessous s'avère ne pas fonctionner.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input
#SingleInstance force
SetKeyDelay, 0, 50


#IfWinExist ahk_exe ArcheAge.exe
^j::
; WinGet, PID, PID, ahk_exe ArcheAge.exe ; retrouve l'ID du processus
; AHKID := "ahk_id " . WinExist("ahk_pid " . PID) ; retrouve l'ID de la fenêtre du jeu
; Loop {
ControlSend,, {s down} ; , % AHKID
Sleep, 200
ControlSend,, {s up} ; , % AHKID
sleep, 400
ControlSend, ahk_parent, {s down} ; , % AHKID
Sleep, 200
ControlSend, ahk_parent, {s up} ; , % AHKID
sleep, 400
; ...
; }
return
#If
F10::ExitApp
my scripts
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

15 Dec 2017, 20:05

Non rien ne se passe. Je te remercie de ton aide et vais poster sur le sous forum que tu m'as envoyé, merci beaucoup de ton temps
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Script pour application en background

15 Dec 2017, 20:19

Blyat wrote:Non rien ne se passe. Je te remercie de ton aide et vais poster sur le sous forum que tu m'as envoyé, merci beaucoup de ton temps
Désolé... A propos, voilà un lien vers un thread récemment actif dans le sub-forum anglophone 'tutorial' concernant les jeux, et dont le titre me semble à propos How to Make AHK Work in Most Games - The Basics. En espérant que ton jeu fasse partie de 'most', crossed fingers
my scripts
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

15 Dec 2017, 20:29

J'essaie le Send and click tool de suite, je te tiens au courant, merci pour le thread!
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

15 Dec 2017, 20:29

Mais selon google beaucoup de gens arrivent a faire marcher des script sur ce jeu via AHK (Jeu = ArcheAge) donc j'espère que on va trouve rune solution..

De plus, AHK est autorisé par l'éditeur du jeu
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

15 Dec 2017, 20:44

Ok alors le TestTool Send et ControlSend marchent mais exclusivement quand je focus la fenêtre. Si je focus une autre fenêtre, rien ne se passera
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Script pour application en background

16 Dec 2017, 11:10

Ok on dois tester voir si c'est un problème de reception...
Si tu activate la fenêtre directement et tu fais send... voir si ça fonctionne... :think:

Code: Select all

Winactivate, ahk_exe ArcheAge.exe
Send R
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

16 Dec 2017, 11:40

Le winactivate marche, le fenêtre prends le focus, par contre la touche n'es pas envoyée
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Script pour application en background

16 Dec 2017, 14:17

Ahh okay... I'll me semble que le jeu ne veux pas detecter les touches...
Hmm...
Sinon on peut essayer d'utiliser ahk_id au lieu de ahk_pid
exemple

Code: Select all

id_programme := WinExist("ahk_pid 5123")
ControlSend, , K, ahk_id %id_programme%

Peut-etre autoit? https://www.autoitscript.com/forum/topi ... ent=166960
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

16 Dec 2017, 14:38

Code: Select all

#NoEnv
SetWorkingDir %A_ScriptDir%
SendMode InputThenPlay


^j::

id_programme := WinExist("ahk_pid 6624")

ControlSend, , A, ahk_id %id_programme%
control+j : rien ne se passe (vérifié le PID au mm moment que de lancer le script)
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

16 Dec 2017, 15:09

Bon apparement ControlSend ne marche pas en background, tout simplement, pour pas mal de jeux. Tu crois que il y a d'autres moyen d'arriver a mes fins ? Je veux juste qu'une succession de touches(abilities) soit frappées en background
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Script pour application en background

16 Dec 2017, 16:05

Hmmm... je sais qu'il y a PostMessage mais je connais pas tous les codes... :/
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

16 Dec 2017, 17:32

Ok,je vais essayer autre chose , par rapport a mon message dans ce post : https://autohotkey.com/boards/viewtopic ... 18&t=41449

Quun a citer le VM étant une solution qui pourrait marcher. saurais tu faire marcher du ControlSend sur Deux client qui seraient en focus en même temps grâce a une Virtual Machine ?
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Script pour application en background

17 Dec 2017, 13:23

ahh ok je vois. Oui fait simplement traiter le VM comme n'importe quel autre fenêtre. :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Blyat
Posts: 24
Joined: 14 Dec 2017, 22:55

Re: Script pour application en background

17 Dec 2017, 18:08

Penses-tu qu'une simple macro clavier corsair (que j'utilise deja mtn et qui marche) fonctionnerai sur deux clients en mm temps séparé sur un VM chacun ? (sur un autre PC que j'laisse tourner) est-ce que les deux clients seraient indépendamment "en focus" ?
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Script pour application en background

17 Dec 2017, 18:25

Théoriquement, tu peux avoir 2 VM dont les fenêtres sont en focus “virtuellement”...
Et le host aurai ahk qui contrôle les VM...
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]

Return to “J'ai besoin d'aide”

Who is online

Users browsing this forum: No registered users and 29 guests