Bonjour
je suis entrain de créer une nouvelle application (HTA)avec du vbscript dedans
et je cherche comment mettre deux boutons (+/-) pour baisser et monter le volume
quelqu'un aurait une piste
merci d'avance
Version imprimable
Bonjour
je suis entrain de créer une nouvelle application (HTA)avec du vbscript dedans
et je cherche comment mettre deux boutons (+/-) pour baisser et monter le volume
quelqu'un aurait une piste
merci d'avance
bonjour,
le contrôle spinbutton pourrait faire l'affaire
exemple hta :
ce contrôle fait partie de la "Microsoft Forms 2.0 Object library"Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 <html> <head> <title> objects </title> <HTA:Application /> <script language="vbscript"> sub spntest_change txtspinvalue.value = spntest.value end sub </script> </head> <body> Spin value:<input type="text" name="txtspinvalue"> <object id="spntest" classid="clsid:79176fb0-b7f2-11ce-97ef-00aa006d2776" codebase="http://activex.microsoft.com/controls/mspert10.cab" > </object> </body> </html>
Bonjour ommen999
le bouton sympa mais ca ne change page pas le volume :calim2:
travaillant sur vba habituellement je me doute que ca doit être un peu plus compliqué c'est la partie vbs que je cherche mais je ne trouve rien
merci pour le coup de main
je cherche toujours
Bonjour a tous
voila j'ai glaner ici et la des méthode utilisant du WSH dans un fichier vbs
Attention c'est valable pour seven pour inferieur c'est "SndVol32"
exemple de fichier VBS seul
seul problème le WSH n'est pas compatible avec un hta étant donné que les fonction vbs sont interne dans le HTACode:
1
2
3
4
5 set oShell = CreateObject("WScript.Shell") oShell.run"%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App. WScript.Sleep 100 'Waits For The Program To Open oShell.SendKeys("{PGUP}") 'Turns Up The Volume 20, If It Is Muted Then It Will Unmute It oShell.SendKeys"%{F4}" ' ALT
donc j'utilise la fonction shellececute
et voila le code
ca ouvre bien le panneau de sonCode:
1
2
3
4
5
6 Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "C:\Windows\System32\SndVol.exe" , "", "", "runas", 1 objShell.SendKeys("{UP}") 'Turns Up The Volume 20, If It Is Muted Then It Will Unmute It objShell.SendKeys"%{F4}" ' ALT
seul problème objshell ne gère pas le sendkey c'est en tout cas l'erreur qui est affichée
quelqu'un a une idée ?
:salut:
A la limite essayer ceci :mouarf:Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 <html> <head> <HTA:APPLICATION APPLICATIONNAME="Volume + -" BORDER="THIN" BORDERSTYLE="NORMAL" ICON="SndVol.exe" INNERBORDER="NO" MAXIMIZEBUTTON="NO" MINIMIZEBUTTON="NO" SCROLL="NO" SELECTION="NO" SINGLEINSTANCE="YES"/> <title> Volume + - </title> <SCRIPT LANGUAGE="VBScript"> ' Position screen Const WinWidth = 265, WinHeight = 198 ' dialog size Const pxLeft = 111, pxTop = 55 ' positioning window.ResizeTo WinWidth,WinHeight window.MoveTo pxLeft,pxTop </SCRIPT> <script language="vbscript"> '************************************************************************************ Sub window_onload() CenterWindow 200,100 End Sub '************************************************************************************ Sub Sleep(MSecs)' Fonction pour faire une pause car wscript.sleep ne marche pas dans un HTA Set fso = CreateObject("Scripting.FileSystemObject") Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2) Dim tempName : tempName = "Sleeper.vbs" If Not Fso.FileExists(tempFolder&"\"&tempName) Then Set objOutputFile = fso.CreateTextFile(tempFolder&"\"&tempName, True) objOutputFile.Write "wscript.sleep WScript.Arguments(0)" objOutputFile.Close End If CreateObject("WScript.Shell").Run tempFolder&"\"&tempName &" "& MSecs,1,True End Sub '************************************************************************************ Sub VolumeUP() set oShell = CreateObject("WScript.Shell") oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App. Sleep 1000 'Waits For The Program To Open oShell.SendKeys("{UP}") 'Turns Up The Volume 20, If It Is Muted Then It Will Unmute It Sleep 1000 oShell.SendKeys"%{F4}" ' ALT + F4 End Sub '************************************************************************************ Sub VolumeDOWN() set oShell = CreateObject("WScript.Shell") oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App. Sleep 1000 'Waits For The Program To Open oShell.SendKeys("{DOWN}") 'Turns Up The Volume 20, If It Is Muted Then It Will Unmute It Sleep 1000 oShell.SendKeys"%{F4}" ' ALT + F4 End Sub '************************************************************************************* Sub CenterWindow(x,y) Dim iLeft,itop window.resizeTo x,y iLeft = window.screen.availWidth/2 - x/2 itop = window.screen.availHeight/2 - y/2 window.moveTo ileft,itop End Sub '************************************************************************************ </script> </head> <body> <center> <BUTTON style="background: Green; color: white;" onClick="VolumeUP()" style="WIDTH: 60px; HEIGHT: 30px">Volume +</BUTTON> <BUTTON style="background: Blue; color: white;" onClick="VolumeDOWN()" style="WIDTH: 60px; HEIGHT: 30px">Volume -</BUTTON> </center> </body> </html>
En toutes rigueurs, pour faire des sauts de 20%, les SendKeys
oShell.SendKeys("{PGUP}") volume +20%
oShell.SendKeys("{PGDN}") volume -20%
oShell.SendKeys(" " & chr(173)) permet de couper/remettre le son (bascule)
oShell.SendKeys("{HOME}") volume maximum 100%
oShell.SendKeys("{END}") volume minimum 0%
:salut:
En tenant compte de la remarque de ProgElecT :king: :plusser:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 <html> <head> <HTA:APPLICATION APPLICATIONNAME="Volume + - ON/OFF" BORDER="THIN" BORDERSTYLE="NORMAL" ICON="SndVol.exe" INNERBORDER="NO" MAXIMIZEBUTTON="NO" MINIMIZEBUTTON="NO" SCROLL="NO" SELECTION="NO" SINGLEINSTANCE="YES"/> <title>Volume + - ON/OFF </title> <script language="vbscript"> '************************************************************************************ Sub window_onload() CenterWindow 250,150 End Sub '************************************************************************************ Sub Sleep(MSecs)' Fonction pour faire une pause car wscript.sleep ne marche pas dans un HTA Set fso = CreateObject("Scripting.FileSystemObject") Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2) Dim tempName : tempName = "Sleeper.vbs" If Not Fso.FileExists(tempFolder&"\"&tempName) Then Set objOutputFile = fso.CreateTextFile(tempFolder&"\"&tempName, True) objOutputFile.Write "wscript.sleep WScript.Arguments(0)" objOutputFile.Close End If CreateObject("WScript.Shell").Run tempFolder&"\"&tempName &" "& MSecs,1,True End Sub '************************************************************************************ Sub Volume(Param) set oShell = CreateObject("WScript.Shell") Select Case Param Case "MAX" oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App. Sleep 2000 'Waits For The Program To Open oShell.SendKeys("{HOME}")' volume maximum 100% Sleep 100 oShell.SendKeys"%{F4}" ' ALT + F4 Case "MIN" oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App. Sleep 2000 'Waits For The Program To Open oShell.SendKeys("{END}") 'volume minimum 0% Sleep 1000 oShell.SendKeys"%{F4}" ' ALT + F4 Case "UP" oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App. Sleep 2000 'Waits For The Program To Open oShell.SendKeys("{PGUP}") 'volume +20% Sleep 1000 oShell.SendKeys"%{F4}" ' ALT + F4 Case "DOWN" oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App. Sleep 2000 'Waits For The Program To Open oShell.SendKeys("{PGDN}") 'Turns Up The Volume 20, If It Is Muted Then It Will Unmute It Sleep 1000 oShell.SendKeys"%{F4}" ' ALT + F4 Case "MUTE" oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App. Sleep 1000 'Waits For The Program To Open oShell.SendKeys(" " & chr(173)) 'permet de couper/remettre le son (bascule) Sleep 1000 oShell.SendKeys"%{F4}" ' ALT + F4 End select End Sub '************************************************************************************* Sub CenterWindow(x,y) Dim iLeft,itop window.resizeTo x,y iLeft = window.screen.availWidth/2 - x/2 itop = window.screen.availHeight/2 - y/2 window.moveTo ileft,itop End Sub '************************************************************************************ </script> </head> <body> <center> <BUTTON style="background: Red; color: white;" onClick="Call Volume('MAX')" style="WIDTH: 85px; HEIGHT: 30px">Volume MAX</BUTTON> <BUTTON style="background: Blue; color: white;" onClick="Call Volume('MIN')" style="WIDTH: 85px; HEIGHT: 30px">Volume MIN</BUTTON> <BUTTON style="background: Green; color: white;" onClick="Call Volume('UP')" style="WIDTH: 85px; HEIGHT: 30px">Volume +20%</BUTTON> <BUTTON style="background: Orange; color: white;" onClick="Call Volume('DOWN')" style="WIDTH: 85px; HEIGHT: 30px">Volume -20%</BUTTON> <BUTTON style="background: DarkOrange; color: white;" onClick="Call Volume('MUTE')" style="WIDTH: 85px; HEIGHT: 30px">ON/OFF</BUTTON> </center> </body> </html>
il est inutile de lancer SndVolxx pour contrôler le volume du son
il suffit de tirer parti du fait que windows sait gérer les claviers multimedia
qui comportent justement des boutons de contrôle du volume et pas
simplement la bascule du mute
donc :
la difficulté tient au fait qu'il est impossible en vbs de lire le niveau courant du volume.Code:
1
2
3
4
5 Set WshShell = CreateObject("WScript.Shell") WshShell.SendKeys chr(173) ' mute WshShell.SendKeys chr(174) ' baisse le volume WshShell.SendKeys chr(175) ' monte le volume WshShell.SendKeys "{" & chr(174) & " 25}" ' baisse le volume au niveau 0 (25 x chr(174))
donc à l'initialisation du hta, il faut prévoir un étalonnement du spin bouton en forçant
le volume au niveau zéro.
chaque keycode modifie le volume avec un pas de 4% d'où le 25 pour assurer le coup...;)
Salut
:ccool: omen999
Ben cela diffère d'un ordinateur à l'autre pour avoir 20% moi il me faut passer 10 fois le KeyCode
La Sub Sleep(MSecs) devient inutile (reste quelle est bien pratique quand on a besoin de l'équivalent de Doevents (VB6)Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Sub Volume(Param) set oShell = CreateObject("WScript.Shell") Select Case Param Case "MAX" oShell.SendKeys "{" & chr(175) & " 50}" ' volume maximum 100% Case "MIN" oShell.SendKeys "{" & chr(174) & " 50}" 'volume minimum 0% Case "UP" oShell.SendKeys "{" & chr(175) & " 10}" 'volume +20% Case "DOWN" oShell.SendKeys "{" & chr(174) & " 10}" 'volume +20% Case "MUTE" oShell.SendKeys chr(173) 'permet de couper/remettre le son (bascule) End select End Sub
:salut:
Avec le dernier code de ProgElecT , ça devient plus souple et plus simple et on n'a plus aussi besoin d'un Sleep en HTA :king: :plusser:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 <html> <head> <HTA:APPLICATION APPLICATIONNAME="Volume + - ON/OFF" BORDER="THIN" BORDERSTYLE="NORMAL" ICON="SndVol.exe" INNERBORDER="NO" MAXIMIZEBUTTON="NO" MINIMIZEBUTTON="NO" SCROLL="NO" SELECTION="NO" SINGLEINSTANCE="YES"/> <title>Volume + - ON/OFF </title> <script language="vbscript"> '************************************************************************************ Sub window_onload() CenterWindow 250,150 End Sub '************************************************************************************ Sub Volume(Param) set oShell = CreateObject("WScript.Shell") Select Case Param Case "MAX" oShell.SendKeys "{" & chr(175) & " 50}" ' volume maximum 100% Case "MIN" oShell.SendKeys "{" & chr(174) & " 50}" 'volume minimum 0% Case "UP" oShell.SendKeys "{" & chr(175) & " 10}" 'volume +20% Case "DOWN" oShell.SendKeys "{" & chr(174) & " 10}" 'volume +20% Case "MUTE" oShell.SendKeys chr(173) 'permet de couper/remettre le son (bascule) End select End Sub '************************************************************************************* Sub CenterWindow(x,y) Dim iLeft,itop window.resizeTo x,y iLeft = window.screen.availWidth/2 - x/2 itop = window.screen.availHeight/2 - y/2 window.moveTo ileft,itop End Sub '************************************************************************************ </script> </head> <body> <center> <BUTTON style="background: Red; color: white;" onClick="Call Volume('MAX')" style="WIDTH: 85px; HEIGHT: 30px">Volume MAX</BUTTON> <BUTTON style="background: Blue; color: white;" onClick="Call Volume('MIN')" style="WIDTH: 85px; HEIGHT: 30px">Volume MIN</BUTTON> <BUTTON style="background: Green; color: white;" onClick="Call Volume('UP')" style="WIDTH: 85px; HEIGHT: 30px">Volume +20%</BUTTON> <BUTTON style="background: Orange; color: white;" onClick="Call Volume('DOWN')" style="WIDTH: 85px; HEIGHT: 30px">Volume -20%</BUTTON> <BUTTON style="background: DarkOrange; color: white;" onClick="Call Volume('MUTE')" style="WIDTH: 85px; HEIGHT: 30px">ON/OFF</BUTTON> </center> </body> </html>
je vais regarder vos deux dernier exemple
en attendant regardez comment je coupe les sons system
et regardes aussi le fait que j'utilise un autre object que le wscripshell
set oShell = CreateObject("WScript.Shell")
Set objShell = CreateObject("Shell.Application")
cela me permet de rendre visible ou invisible la fenetre sndvol.exe
qu'en pensez vous ?Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 <html> <head> <HTA:APPLICATION APPLICATIONNAME="Volume + -" BORDER="THIN" BORDERSTYLE="NORMAL" ICON="SndVol.exe" INNERBORDER="NO" MAXIMIZEBUTTON="NO" MINIMIZEBUTTON="NO" SCROLL="NO" SELECTION="NO" SINGLEINSTANCE="YES"/> <title> Volume + - </title> <SCRIPT LANGUAGE="VBScript"> ' Position screen Const WinWidth = 265, WinHeight = 198 ' dialog size Const pxLeft = 111, pxTop = 55 ' positioning window.ResizeTo WinWidth,WinHeight window.MoveTo pxLeft,pxTop </SCRIPT> <script language="vbscript"> '******************************************************************************************************** Sub window_onload() CenterWindow 200,100 coupe_Son_System End Sub '******************************************************************************************************** Sub window_onUnload() remet_son_system End Sub '******************************************************************************************************** sub remet_son_system() 'on remet les sons system a la sortie de l'application set oShell = CreateObject("WScript.Shell") Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "C:\Windows\System32\SndVol.exe" , "", "", "runas", 0 Sleep 700 'Waits For The Program To Open for i=1 to 3 oShell.SendKeys"{TAB}" ' remet les sons system next for i=1to 5 oShell.SendKeys"{PGUP}" ' next oShell.SendKeys"%{F4}" ' ALT + F4 End Sub '********************************************************************************************************* ' on va couper les sons systeme sinon des beep a tout va achaque clic sub coupe_Son_System() set oShell = CreateObject("WScript.Shell") Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "C:\Windows\System32\SndVol.exe" , "", "", "runas", 0 Sleep 700 'Waits For The Program To Open for i=1 to 3 oShell.SendKeys"{TAB}" ' 'on ateint la partie des sons system avec la touche tab next for i=1to 5 oShell.SendKeys"{PGDN}" ' on baisse a fond les sons system next oShell.SendKeys"%{F4}" ' ALT + F4'on ferme la fenbetre sndvol end sub '********************************************************************************************************* Sub VolumeDOWN() set oShell = CreateObject("WScript.Shell") Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "C:\Windows\System32\SndVol.exe" , "", "", "runas", 0 Sleep 700 'Waits For The Program To Open for i = 1 to 5 oShell.SendKeys("{DOWN}") 'on baisse de 5 crans le son hautparleur next Sleep 700 oShell.SendKeys"%{F4}" ' ALT + F4' on quitte sndvol.exe End Sub '******************************************************************************************************* Sub Sleep(MSecs)' Fonction pour faire une pause car wscript.sleep ne marche pas dans un HTA Set fso = CreateObject("Scripting.FileSystemObject") Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2) Dim tempName : tempName = "Sleeper.vbs" If Not Fso.FileExists(tempFolder&"\"&tempName) Then Set objOutputFile = fso.CreateTextFile(tempFolder&"\"&tempName, True) objOutputFile.Write "wscript.sleep WScript.Arguments(0)" objOutputFile.Close End If CreateObject("WScript.Shell").Run tempFolder&"\"&tempName &" "& MSecs,1,True End Sub '******************************************************************************************************* Sub VolumeUP() set oShell = CreateObject("WScript.Shell") Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "C:\Windows\System32\SndVol.exe" , "", "", "runas", 0 Sleep 700 'Waits For The Program To Open for i= 1 to 3 oShell.SendKeys("{UP}") 'on monte de 3 crans le son hautparleur next Sleep 1000 oShell.SendKeys"%{F4}" ' ALT + F4'on quitte sndvol.exe End Sub '******************************************************************************************************* Sub CenterWindow(x,y) Dim iLeft,itop window.resizeTo x,y iLeft = window.screen.availWidth/2 - x/2 itop = window.screen.availHeight/2 - y/2 window.moveTo ileft,itop End Sub '******************************************************************************************************* </script> </head> <body> <center> <BUTTON style="background: Green; color: white;" onClick="VolumeUP()" style="WIDTH: 60px; HEIGHT: 30px">Volume +</BUTTON> <BUTTON style="background: Blue; color: white;" onClick="VolumeDOWN()" style="WIDTH: 60px; HEIGHT: 30px">Volume -</BUTTON> </center> </body> </html>
RE
Autant pour moi
la méthode ProgElecT est parfaite pas de fenêtre ,pas de sleep adapté dans ton code hackoofr c'est parfait
purée pourquoi Ya pas ca dans la Faq voila une source a partagé et qui mérite sa place non de dieu
c'est pas grand chose mais ca fait 3 jours que je bosse dessus et on trouve ca nul part
par contre une explication sur le numéraire après la keys me serait utile pour ma compréhension
+1 pour tout les deux :applo:
purré de purré 3 jours j'y crois pas :mouarf:
EDIT: Allez je garde la dernière méthode en espérant que les keys soit identiques pour tout les ordis
Merci a tout les deux
:pastaper:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 Sub Volume(Param1,Param2,Param3) set oShell = CreateObject("WScript.Shell") oShell.SendKeys Param1 & chr(Param2) & Param3 '--------------------------- MEMO ---------------------------------- 'oShell.SendKeys "{" & chr(175) & " 50}" ' volume maximum 100% 'oShell.SendKeys "{" & chr(174) & " 50}" 'volume minimum 0% 'oShell.SendKeys "{" & chr(175) & " 10}" 'volume +20% 'oShell.SendKeys "{" & chr(174) & " 10}" 'volume +20% 'oShell.SendKeys chr(173) 'permet de couper/remettre le son (bascule) End Sub '.............................. <BUTTON onClick="Call Volume('{','175',' 50}')" style="background: Red; color: white;WIDTH: 85px; HEIGHT: 30px">Volume MAX</BUTTON> <BUTTON onClick="Call Volume('{','174',' 50}')" style="background: Blue; color: white;WIDTH: 85px; HEIGHT: 30px">Volume MIN</BUTTON> <BUTTON onClick="Call Volume('{','175',' 10}')" style="background: Green; color: white;WIDTH: 85px; HEIGHT: 30px">Volume +20%</BUTTON> <BUTTON onClick="Call Volume('{','174',' 10}')" style="background: Orange; color: white;WIDTH: 85px; HEIGHT: 30px">Volume -20%</BUTTON> <BUTTON onClick="Call Volume('','173','')" style="background: DarkOrange; color: white;WIDTH: 85px; HEIGHT: 30px">ON/OFF</BUTTON> '..............................
Bonjour ProgElecT
c'est nikel et a mettre dans les contrib pour ne plus avoir a chercher des plombes
respect!
en plus j'était en train de chercher la syntaxe pour injecter plusieurs arguments du bouton a la sub en vbs tu viens de le faire
respect!
merci encore a toi et hackoofr
Au plaisir
mon code initial avait été écrit sous xp sp3Citation:
Ben cela diffère d'un ordinateur à l'autre pour avoir 20% moi il me faut passer 10 fois le KeyCode
je viens de tester sous seven sp1, effectivement avec cette version le pas est réduit de moitié 2% ou lieu de 4. :aie:
Salut
@omen999, dans tous les cas tu est l’initiateur de la simplification (code et commentaire de ton post N°8 ou tu indiques qu'il est inutile de lancer SndVol)