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
Code : Tout sélectionner
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=D:\dev\autoit\123clap.exe
#AutoIt3Wrapper_Allow_Decompile=n
#AutoIt3Wrapper_Res_Comment=http://mclaveau.com Michel Claveau Informatique
#AutoIt3Wrapper_Res_Description=1, 2, 3 Clap !
#AutoIt3Wrapper_Res_Fileversion=0.3.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Michel Claveau Informatique
#AutoIt3Wrapper_Res_Language=1036
#AutoIt3Wrapper_Run_AU3Check=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#Include <string.au3>
$cde1=""
$cde2=""
$cde3=""
if $CmdLine[0]>0 then
$cde1=$CmdLine[1]
endif
if $CmdLine[0]>1 then
$cde2=$CmdLine[2]
endif
if $CmdLine[0]>2 then
$cde3=$CmdLine[3]
endif
$VoiceActivationLevel = 40
$level=0
Func _mciSendString($lpszCommand, $lpszReturnString, $cchReturn, $hwndCallback)
Return DllCall("winmm.dll", "long", "mciSendStringA", "str", $lpszCommand, "str", $lpszReturnString, "long", $cchReturn, "long", 0)
EndFunc
Func _mciShowError($mciError,$add = "test")
Dim $errStr
$errStr = _StringRepeat(" ", 256)
$Result = DllCall("winmm.dll", "long", "mciGetErrorStringA", "long", $mciError, "string", $errStr, "long", StringLen($errStr))
MsgBox(0, "MCI "&$add, "MCI Error Number " & $mciError & ":" & $Result[2])
EndFunc
Func ClapCheck()
Global $lpszCommand,$lpszReturnString,$cchReturn,$level
$level=0
$mciError = _mciSendString("status tempwave level", $lpszReturnString, $cchReturn, 0)
If $mciError[0]<>0 Then
MsgBox(0,"Erreur MCI 37 ; ",$mciError[0])
EndIf
If $mciError[2]>0 Then
$level=$mciError[2]
EndIf
If $level >= $VoiceActivationLevel Then
$retombe=$level
While $retombe >= $VoiceActivationLevel
$mciError = _mciSendString("status tempwave level", $lpszReturnString, $cchReturn, 0)
$retombe = $mciError[2]
sleep(6)
WEnd
EndIf
EndFunc
$lpszReturnString = _StringRepeat(" ", 256)
$cchReturn = StringLen($lpszReturnString)
$mciError = _mciSendString("open new type waveaudio alias tempwave", $lpszReturnString, $cchReturn, 0);
If $mciError[0] <> 0 Then
_mciShowError($mciError[0],"Startup Error")
Exit
EndIf
$interv=20
$delaimaxientre2clics = Int(600/$interv) ; en millisecondes
$ClapCount = 0
$i=$delaimaxientre2clics
Global $level
$level=0
While 1
Sleep($interv)
$i-=1
If $i<=0 Then
If $ClapCount>0 Then
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
If $ClapCount>3 Then
MsgBox(0,"Nb Claps",$ClapCount,1)
EndIf
;ToolTip($ClapCount,180,180,"Nb Claps comptés",0)
If $ClapCount>3 Then
MsgBox(0,"plus de 3 Claps","Fin du programme",2)
ExitLoop
EndIf
EndIf
$i=$delaimaxientre2clics
$ClapCount=0
EndIf
$level=0
ClapCheck()
If $level >= $VoiceActivationLevel Then
$ClapCount +=1
$i=$delaimaxientre2clics
;ToolTip($ClapCount & " " & $level & " " & $i,80,80,"Nb Claps",0)
EndIf
WEnd
Exit