Problème de boucle sur un script

Poser vos questions de programmation en AutoHotkey
raidgo
Posts: 1
Joined: 25 Nov 2022, 06:53

Problème de boucle sur un script

Post by raidgo » 25 Nov 2022, 07:06

Bonjour à toute la communauté.

Je débute avec AHK et la programmation en général, donc s'il vous plait soyez indulgents ;)

Pour mon boulot, j'ai commencé à écrire un script me permettant d'automatiser une tâche pénible.

Ce script ouvre une boite de dialogue me demandant combien de chauffeurs ils doit traiter. S'en suit des déplacements à la souris et des envois de clavier. Jusque là tout fonctionne.

C'est fonctionnel pour le premier conducteur. Donc si ma valeur tapée en boîte de dialogue est 1, le script est fonctionnel. Pareil pour 2.

Le problème c'est que j'aimerai faire une boucle si UserInput > 2 et qu'il s'incrémente automatiquement en fonction de la saisie de UserInput. (Admettons je lui déclare 30 chauffeurs, il effectue l'opétation 30x en incrémentant une variable appelée i plus bas de 1.

Je ne suis pas sur d'être clair dans mes propos...

Code: Select all

^j::   ;Lorsque la commande CTRL + J est envoyée le logiciel va changer le pays du conducteur sur France, sauvegarder et passer au suivant.
InputBox, UserInput, Hackoscan, Renseignez le nombre de conducteurs., , 300, 200
if ErrorLevel
    
	{
	
	MsgBox, A bientôt.
	
	}
	
else
    {
	
	MsgBox, Vous avez déclaré "%UserInput%" conducteur(s)

if (UserInput = 1)  ; Etape 1
	
	{
	
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	Send, +{Click, 100 195, 2}
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Return
	
	}

else if (UserInput = 2)  ; Etape 2
	
	{
	
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	Send, +{Click, 100 195, 2}
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	
	Send, {down}
	Send, +{Click, 55 56} 
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Return
	
	}

else if (UserInput > 2)

	{

	Send, +{Click, 100 195}
	Send, {PgUp 10}
	Send, +{Click, 100 195, 2}
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	
	Send, {down}
	Send, +{Click, 55 56} 
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	
[b]Que renseigner ici pour démarrer la boucle?	[/b]
	
	{
	Send, {down [b]i[/b]} ; Ici la variable i doit s'incrémenter de 1 à chaque boucle tant que UserInput n'est pas atteint
	Send, +{Click, 55 56} 
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	Return

	}
	
Return
	
	}

	}
	
Return
[Mod edit: + [code][/code] tags.]

User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Problème de boucle sur un script

Post by joedf » 25 Nov 2022, 11:11

Essayez ceci?
J'ai ajouté un Loop, %UserInput% et arrangé les { et }

Code: Select all

^j::   ;Lorsque la commande CTRL + J est envoyée le logiciel va changer le pays du conducteur sur France, sauvegarder et passer au suivant.
InputBox, UserInput, Hackoscan, Renseignez le nombre de conducteurs., , 300, 200
if ErrorLevel
{
	MsgBox, A bientôt.
}
else
{
	MsgBox, Vous avez déclaré "%UserInput%" conducteur(s)
}

if (UserInput = 1)  ; Etape 1
{
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	Send, +{Click, 100 195, 2}
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Return
}
else if (UserInput = 2)  ; Etape 2
{
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	Send, +{Click, 100 195, 2}
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	
	Send, {down}
	Send, +{Click, 55 56} 
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Return
}
else if (UserInput > 2)
{
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	Send, +{Click, 100 195, 2}
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	
	Send, {down}
	Send, +{Click, 55 56} 
	Send, +{Click, 700 192}
	Send, f r
	Send, {Enter}
	Send, +{Click, 140 60}
	Sleep, 7000
	Send, +{Click, 100 195}
	Send, {PgUp 10}
	
	Loop, %UserInput%
	{
		Send, {down [b]%A_Index%[/b]} ; Ici la variable i doit s'incrémenter de 1 à chaque boucle tant que UserInput n'est pas atteint
		Send, +{Click, 55 56} 
		Send, +{Click, 700 192}
		Send, f r
		Send, {Enter}
		Send, +{Click, 140 60}
		Sleep, 7000
		Send, +{Click, 100 195}
		Send, {PgUp 10}
	}
	
	Return
}
Return
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]

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Problème de boucle sur un script

Post by flyingDman » 25 Nov 2022, 16:32

Quel est le rôle des b ?

Code: Select all

[b] .... [/b]
S'il y en a pas, enlevez.
14.3 & 1.3.7

Post Reply

Return to “J'ai besoin d'aide”