[Ex] 1,2,3 Clap !

Partagez vos scripts, et vos applications AutoIt.
Règles du forum
.
Répondre
Avatar du membre
MClaveau
AutoIt MVPs (MVP)
AutoIt MVPs (MVP)
Messages : 28
Enregistré le : ven. 08 févr. 2008 22:11
Status : Hors ligne

[Ex] 1,2,3 Clap !

#1

Message par MClaveau »

Bonjour !

D'après une idée du forum américain. Mais, j'ai largement modifié et adapté le code.
Il faut avoir un microphone, ouvert, sur son ordinateur.

Deux modes d'utilisation :
- lancement direct ; taper alors 1, 2, 3 fois dans vos mains (ou plus de 3 fois pour sortir)
- après compilation, lancer l'exécutable avec 1, 2 ou 3 paramètres, qui correspondront à 3 commandes possibles (selon que l'on tape 1, 2 ou 3 fois dans ses mains).

Exemple :
c:\123clap notepad calc http://mclaveau.com/batch

@-salutations

Michel Claveau
► Afficher le texte
@-salutations (pas de messages perso ; merci)
--

Michel Claveau
Avatar du membre
arrkhan
Niveau 8
Niveau 8
Messages : 528
Enregistré le : sam. 17 nov. 2007 03:30
Status : Hors ligne

Re: 1,2,3 Clap !

#2

Message par arrkhan »

hihi, ca fonctionne relativement bien, mais c'est assez compliqué de trouver le bon rythme pour claquer dans ses mains, dès que je trouve le temps, je tenterai de me servir de ce script pour le faire fonctionner avec le "Microsoft English Recognizerv5.1", ca peut etre plus sympa de lui parler plutôt que de s'exploser les mains ^^
tolf
Niveau 7
Niveau 7
Messages : 318
Enregistré le : ven. 15 févr. 2008 12:25
Localisation : Paris
Status : Hors ligne

Re: 1,2,3 Clap !

#3

Message par tolf »

Bonjour,

Voici quelques modifications pour alléger le code :
Au lieu d'avoir ceci à la fin :

Code : Tout sélectionner

             If $ClapCount=1 Then
                If $cde1<>"" Then
                    ;Run(@ComSpec & " /c " & $cde1, "", @SW_HIDE)
                    Run(@ComSpec & ' /cstart "" ' & $cde1, "", @SW_HIDE)
                Else
                    MsgBox(0,"Nb Claps",$ClapCount,1)
                EndIf
            EndIf
            If $ClapCount=2 Then
                If $cde2<>"" Then
                    Run(@ComSpec & ' /cstart "" ' & $cde2, "", @SW_HIDE)
                Else
                    MsgBox(0,"Nb Claps",$ClapCount,1)
                EndIf
            EndIf
            If $ClapCount=3 Then
                If $cde3<>"" Then
                    Run(@ComSpec & ' /cstart "" ' & $cde3, "", @SW_HIDE)
                Else
                    MsgBox(0,"Nb Claps",$ClapCount,1)
                EndIf
            EndIf
Tu peux créer une fonction regroupant ton "Run" et ta "MsgBox" pour obtenir ceci :

Code : Tout sélectionner

<div class="autoit" id="{CB}" style="font-family: monospace;">             <span style="color: #0000FF; font-weight: bold;">If</span> <span style="font-weight: bold; color: #AA0000;">$ClapCount</span>=<span style="color: #AC00A9; font-style: italic; font-weight: bold;">1</span> <span style="color: #0000FF; font-weight: bold;">Then</span> Run_ET_MsgBox<span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$cde1</span>, <span style="font-weight: bold; color: #AA0000;">$ClapCount</span><span style="color: #FF0000; font-weight: bold;">&#41;</span><br />            <span style="color: #0000FF; font-weight: bold;">If</span> <span style="font-weight: bold; color: #AA0000;">$ClapCount</span>=<span style="color: #AC00A9; font-style: italic; font-weight: bold;">2</span> <span style="color: #0000FF; font-weight: bold;">Then</span> Run_ET_MsgBox<span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$cde2</span>, <span style="font-weight: bold; color: #AA0000;">$ClapCount</span><span style="color: #FF0000; font-weight: bold;">&#41;</span><br />            <span style="color: #0000FF; font-weight: bold;">If</span> <span style="font-weight: bold; color: #AA0000;">$ClapCount</span>=<span style="color: #AC00A9; font-style: italic; font-weight: bold;">3</span> <span style="color: #0000FF; font-weight: bold;">Then</span> Run_ET_MsgBox<span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">$cde3</span>, <span style="font-weight: bold; color: #AA0000;">$ClapCount</span><span style="color: #FF0000; font-weight: bold;">&#41;</span></div>
et voici la fonction qui s'occupe du "run" et de la "msgbox" :

Code : Tout sélectionner

<div class="autoit" id="{CB}" style="font-family: monospace;"><div class=<span style="font-weight: bold; color: #008080;">"autoit"</span> id=<span style="font-weight: bold; color: #008080;">"{CB}"</span> style=<span style="font-weight: bold; color: #008080;">"font-family: monospace;"</span>><span style=<span style="font-weight: bold; color: #008080;">"color: #0000FF; font-weight: bold;"</span>>Func</span> Run_ET_MsgBox<span style=<span style="font-weight: bold; color: #008080;">"color: #FF0000; font-weight: bold;"</span>>&#<span style="color: #AC00A9; font-style: italic; font-weight: bold;">40</span><span style="font-style: italic; color: #009933;">;</span><span style="font-weight: bold; color: #AA0000;">$variable</span>, <span style="font-weight: bold; color: #AA0000;">$ClapCount</span><span style="color: #FF0000; font-weight: bold;">&#41;</span><br />    <span style="color: #0000FF; font-weight: bold;">If</span> <span style="font-weight: bold; color: #AA0000;">$variable</span><><span style="font-weight: bold; color: #008080;">""</span> <span style="color: #0000FF; font-weight: bold;">Then</span><br />        <span style="color: #000080; font-style: italic; font-weight: bold;">Run</span><span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="font-weight: bold; color: #AA0000;">@ComSpec</span> & <span style="font-weight: bold; color: #008080;">' /cstart "" '</span> & <span style="font-weight: bold; color: #AA0000;">$variable</span>, <span style="font-weight: bold; color: #008080;">""</span>, <span style="font-weight: bold; color: #AA0000;">@SW_HIDE</span><span style="color: #FF0000; font-weight: bold;">&#41;</span><br />    <span style="color: #0000FF; font-weight: bold;">Else</span><br />        <span style="color: #000080; font-style: italic; font-weight: bold;">MsgBox</span><span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="color: #AC00A9; font-style: italic; font-weight: bold;">0</span>,<span style="font-weight: bold; color: #008080;">"Nb Claps"</span>,<span style="font-weight: bold; color: #AA0000;">$ClapCount</span>,<span style="color: #AC00A9; font-style: italic; font-weight: bold;">1</span><span style="color: #FF0000; font-weight: bold;">&#41;</span><br />    <span style="color: #0000FF; font-weight: bold;">EndIf</span><br /><span style="color: #0000FF; font-weight: bold;">EndFunc</span></div></span></div>
De plus, tu peux remplacer ceci :

Code : Tout sélectionner

<div class="autoit" id="{CB}" style="font-family: monospace;"><div class=<span style="font-weight: bold; color: #008080;">"autoit"</span> id=<span style="font-weight: bold; color: #008080;">"{CB}"</span> style=<span style="font-weight: bold; color: #008080;">"font-family: monospace;"</span>>             <span style=<span style="font-weight: bold; color: #008080;">"color: #0000FF; font-weight: bold;"</span>>If</span> <span style=<span style="font-weight: bold; color: #008080;">"font-weight: bold; color: #AA0000;"</span>><span style="font-weight: bold; color: #AA0000;">$ClapCount</span></span>><span style=<span style="font-weight: bold; color: #008080;">"color: #AC00A9; font-style: italic; font-weight: bold;"</span>><span style="color: #AC00A9; font-style: italic; font-weight: bold;">3</span></span> <span style=<span style="font-weight: bold; color: #008080;">"color: #0000FF; font-weight: bold;"</span>>Then</span><br />                <span style=<span style="font-weight: bold; color: #008080;">"color: #000080; font-style: italic; font-weight: bold;"</span>>MsgBox</span><span style=<span style="font-weight: bold; color: #008080;">"color: #FF0000; font-weight: bold;"</span>>&#<span style="color: #AC00A9; font-style: italic; font-weight: bold;">40</span><span style="font-style: italic; color: #009933;">;</span><span style="color: #AC00A9; font-style: italic; font-weight: bold;">0</span>,<span style="font-weight: bold; color: #008080;">"Nb Claps"</span>,<span style="font-weight: bold; color: #AA0000;">$ClapCount</span>,<span style="color: #AC00A9; font-style: italic; font-weight: bold;">1</span><span style="color: #FF0000; font-weight: bold;">&#41;</span><br />            <span style="color: #0000FF; font-weight: bold;">EndIf</span><br />            <span style="font-style: italic; color: #009933;">;ToolTip($ClapCount,180,180,"Nb Claps comptés",0)</span><br />            <span style="color: #0000FF; font-weight: bold;">If</span> <span style="font-weight: bold; color: #AA0000;">$ClapCount</span>><span style="color: #AC00A9; font-style: italic; font-weight: bold;">3</span> <span style="color: #0000FF; font-weight: bold;">Then</span><br />                <span style="color: #000080; font-style: italic; font-weight: bold;">MsgBox</span><span style="color: #FF0000; font-weight: bold;">&#40;</span><span style="color: #AC00A9; font-style: italic; font-weight: bold;">0</span>,<span style="font-weight: bold; color: #008080;">"plus de 3 Claps"</span>,<span style="font-weight: bold; color: #008080;">"Fin du programme"</span>,<span style="color: #AC00A9; font-style: italic; font-weight: bold;">2</span><span style="color: #FF0000; font-weight: bold;">&#41;</span><br />                <span style="color: #0000FF; font-weight: bold;">ExitLoop</span><br />            <span style="color: #0000FF; font-weight: bold;">EndIf</span></div></span></div>
en ne mettant qu'un seul "if...then" :

Code : Tout sélectionner

             If $ClapCount>3 Then
                MsgBox(0,"Nb Claps",$ClapCount,1)
                MsgBox(0,"plus de 3 Claps","Fin du programme",2)
                ExitLoop
            EndIf
Lisez la documentation d'AutoIt en français (et participez svp :mrgreen:) !

Mes UDF :
[/i][/b]
Répondre