Script complexe pour 2 touches

Poser vos questions de programmation en AutoHotkey
6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Script complexe pour 2 touches

Post by 6zerox » 31 Jan 2023, 18:02

Bonjour
J'essaie de réaliser un script mais il me parait complexe alors j'en appelle a vos compétences qui seront bien plus élevées que les miennes

Je souhaiterai réaliser un script qui lorsque j'appuie sur F par exemple cela appuie sur P (un appuie simple sur P) puis appuie sur M (appuie qui reste enfoncé sur M)
Et lorsque je rappuierai sur la touche F cela rappuiera sur P cela relèvera la touche M
Je ne sais pas si je me suis bien exprimé n'hésitez pas si vous avez des questions
Pour le moment j'en suis à

Code: Select all

 f::

Send, {P}
Sleep, 10
Send, {M down}
Send, {P}
Send, {M up}
Ce qui ne semble pas fonctionner du tout comme je le souhaiterai,
Je pense que je ne m'y prends pas de la bonne manière et qu'il faudrait que je découpe en gros en 2 morceaux mon script comme
Partie 1 : j'appuie sur F donc ça appuie sur P et ça reste appuyé sur M
Partie 2 : Si un nouvel appuie sur F existe alors appuyer de nouveau sur P et relâcher M

En espérant pouvoir vous aider un jour en retour
Merci :)

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Script complexe pour 2 touches

Post by DuckingQuack » 01 Feb 2023, 09:37

J'utilise Google translate donc il pourrait y avoir des malentendus. J'ai créé un script qui correspond peut-être à ce que vous demandez, mais je suis au travail et incapable de le tester.
Il vérifie l'état de m lorsque vous appuyez sur f et envoie une commande basée sur l'état actuel de m.

Code: Select all

AHKv1
f::
	if getkeystate(m, t){
		send, p
		send, {m up}
	}
	else{
		send, p
		sleep, 10
		send, {m down}
	}
return
Best of Luck,
The Duck

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 10:22

Hello :)
Thanks you for answer but doesn't work like i want : You do a script when i press F that press P and M but release M i think because if i press F that do "PM"

Thanks you for help and sorry for my english xD
Tu peux essayer sur un word tu verras que quand tu appuies sur F il y a qu'un seul appuie sur P et un seul sur M alors que je voudrai que le bouton M reste enfoncé jusqu'à ce que j'appuie de nouveau sur F
En attente d'autres aides :)

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Script complexe pour 2 touches

Post by DuckingQuack » 01 Feb 2023, 10:49

À partir de Google Translate : Je serai en mesure de créer un meilleur script dans environ 8 heures lorsque je pourrai enfin m'asseoir devant mon PC.
Votre désir est d'utiliser "F" comme raccourci clavier qui, à la première pression, envoie un "P" suivi de l'activation de "M". Ensuite, à la deuxième pression sur "F", vous souhaitez envoyer "P" suivi de la désactivation de "M" ?
Best of Luck,
The Duck

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 11:09

Exactly :)
Thanks you for help

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Script complexe pour 2 touches

Post by DuckingQuack » 01 Feb 2023, 11:14

I can fix that, virtual keys don’t continuously send their key as if you were holding the button down because the keyboard does that. So I’ll add a repeated “m” to the script.
Best of Luck,
The Duck

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Script complexe pour 2 touches

Post by DuckingQuack » 01 Feb 2023, 11:26

Test this and let me know how it goes.

Code: Select all

#Requires AutoHotkey v1.1.33
F1::
If on := !on {
	Send, p
 	SetTimer timer, 10
	} Else {
	Send, p
 	SetTimer timer, Off
	}
Return

timer(){
	Send, m
}
Best of Luck,
The Duck

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 12:20

said me an error in script

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Script complexe pour 2 touches

Post by DuckingQuack » 01 Feb 2023, 12:38

I corrected some syntax mistakes, thank you for your patience. I’m doing this from my phone. Please test this one and let me know how it goes.

Code: Select all

f::
If on := !on {
	Send, p
 	SetTimer, timer, 10
	} Else {
	Send, p
 	SetTimer timer, Off
	}
Return

timer()
{
	Send, m
}
Return
Best of Luck,
The Duck

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 12:42

An new error :p

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Script complexe pour 2 touches

Post by DuckingQuack » 01 Feb 2023, 12:48

@6zerox I may have gotten it right this time.

Code: Select all

f::
If on := !on {
	Send, p
 	SetTimer, timer, 10
	} Else {
	Send, pm
 	SetTimer, timer, Off
	}
Return

timer()
{
	Send, m
}
Return
Last edited by DuckingQuack on 01 Feb 2023, 17:50, edited 2 times in total.
Best of Luck,
The Duck

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 13:26

A new error :)

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 13:31

OH may be because i have version 1.XX ?

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Script complexe pour 2 touches

Post by DuckingQuack » 01 Feb 2023, 13:36

This is a script for AHKv1… I’m more accustomed to writing in AHKv2, which is why I’m having problems, but I’ll test it when I get home. I need to know what the errors are to fix them.
Best of Luck,
The Duck

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 14:22

DuckingQuack wrote:
01 Feb 2023, 11:14
I can fix that, virtual keys don’t continuously send their key as if you were holding the button down because the keyboard does that. So I’ll add a repeated “m” to the script.
Hum sorry but i really need that is only one M on continue and not a lot of M like : if press F press P and release and push M and if press F Again so press P and release and up M
I sais it’s difficult macro for 2 touch xD

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 14:31

DuckingQuack wrote:
01 Feb 2023, 11:14
I can fix that, virtual keys don’t continuously send their key as if you were holding the button down because the keyboard does that. So I’ll add a repeated “m” to the script.
I’ m sorry but i really need it’s only one M continue and not a lot of M :D
I said it’s difficult script for two keys 😂
So to imagine it i can say
If first press F -> Press P and push M (maybe with delay for M but not sur)
If second press F -> press P and up M

Les modérateurs n’hésitez pas à dire si on doit bouger de topic car on parle anglais dans le topic fr désolé
Thanks a lot for your Time :)

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Script complexe pour 2 touches

Post by DuckingQuack » 01 Feb 2023, 18:24

Google Translation in parentheses (Google Traduction entre parenthèses)
@6zerox I've tested each script I've provided and have no errors. Depending on what the error is that you get, it could be an issue on your side. (J'ai testé chaque script que j'ai fourni et je n'ai aucune erreur. Selon l'erreur que vous obtenez, cela pourrait être un problème de votre côté.)

The output of this script when you press "f" and wait a few seconds and press "f" again is:
(La sortie de ce script lorsque vous appuyez sur "f" et attendez quelques secondes et appuyez à nouveau sur "f" est) :
pmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmp

Code: Select all

#Requires AutoHotkey v1.1.33
Esc::ExitApp
f::
If on := !on {
	Send, p
 	SetTimer, timer, 10
	} Else {
	Send, p
 	SetTimer, timer, Off
	}
Return

timer(){
	Send, m
}

If you require a different output result from pressing a single button, please describe it as I have done above. If this was the desired output, then I wish you good luck in resolving your error codes. (Si vous avez besoin d'un résultat de sortie différent en appuyant sur un seul bouton, veuillez le décrire comme je l'ai fait ci-dessus. S'il s'agissait de la sortie souhaitée, je vous souhaite bonne chance pour résoudre vos codes d'erreur.)
Best of Luck,
The Duck

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 18:56

oh my bad i didnt see i can scroll so i dont take the bottom
Thats work you are great ! :)

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Script complexe pour 2 touches

Post by DuckingQuack » 01 Feb 2023, 19:04

6zerox wrote:
01 Feb 2023, 18:56
oh my bad i didnt see i can scroll so i dont take the bottom
Thats work you are great ! :)
:lol: :crazy: :headwall:
You had me very confused all day! lol
Best of Luck,
The Duck

6zerox
Posts: 16
Joined: 31 Jan 2023, 17:53

Re: Script complexe pour 2 touches

Post by 6zerox » 01 Feb 2023, 19:40

Really sory you spend time for nothing because you was in good way (sory again for english)
But you are genius to do it on tel xD

Post Reply

Return to “J'ai besoin d'aide”