Damein Posted February 8, 2011 Posted February 8, 2011 (edited) I was bored and wanted to play with the Level Meter script by taietel so I created this volume control script.I liked how it came out so I added iTunes hotkeys as well for my everyday use.*** EDIT ***I left in a test MsgBox before, it is on line 150, I removed it from the posted code, but not from the downloadable. The line is as follows:MsgBox(0, "Test", $Modifier & $iTunesPlaynPauseHotKey)I would suggest removing so you don't have a random message box for no reason Features:After you active the meter (Alt+v) you will see a bar moving with your mouse, which will also set your master volume up or down, according to which way you move your mouse. Just press Alt+v again to stop the volume meter. Mute button to quickly mute volume.iTunes hotkeys*** Images for mute/un-mute buttons uploaded as well. ***Screen shots:Here is the first GUI shown (Un-muted):Muted:Here is the GUI with the level meter active (Controlled by mouse up/down):And here is the iTunes Hotkey GUI:All in all, it was just for fun, but someone might find it handy.(I am not the most organized coder, but I tried )Script:expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <VolumeMeter.au3> $KeyList = "F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|`|1|2|3|4|5|6|7|8|9|0|-|=|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|[|]|;|'|,|.|/|NUMPADDIV|NUMPADMULT|NUMPADSUB|NUMPADADD|NUMPADENTER|NUMPADDOT|NUMPAD0|NUMPAD1|NUMPAD2|NUMPAD3|NUMPAD4|NUMPAD5|NUMPAD6|NUMPAD7|NUMPAD8|NUMPAD9" HotKeySet("!{v}", "VolumeControl") ; Hotkey: ALT+V for controlling the volume HotKeySet("^{g}", "ShowGUI") ; Hotkey: CTRL+G for displaying GUI HotKeySet("{ESC}", "CloseGUI") Global $Gui, $s1, $Amount, $MuteButton, $Pos, $a, $status, $status2, $mute, $HotKeyGUIOpen, $HotKeyGUI, $HotkeyCheckBox, $WinModifierKey, $ControlModifierKey, $AltModifierKey, $ShiftModifierKey, $Modifier, $iTunesPlaynPauseHotkeyList, $iTunesNextHotkeyList, $iTunesPreviousHotkeyList,$iTunesPlaynPauseHotKey, $iTunesNextHotkey, $iTunesPreviousHotkey, $iTunesWinModifierKey, $iTunesControlModifierKey, $iTunesAltModifierKey, $iTunesShiftModifierKey ; State variables TrayTip("Hotkey Information", "To open the hotkey selection, click the checkbox in the bottom right-hand corner.", 1, 1) ; Display tooltip Opt("GUIOnEventMode", 1) ; Set to OnEventMode $iTunesVolumePercent = 10 ; Set volume percent for iTunes to increase/decrease accordingly While 1 ; Begin Idle Sleep(1000) ; Idle WEnd ; End Idle Func ShowGUI() ; Begin GUI display $status2 +=1 If $status2 < 2 Then GuiDelete($Gui) ; Delete existing GUI's $pos = MouseGetPos() ; Get current mouse position for placement of GUI $gui = GUICreate("Volume Control", 120, 90,$Pos[0]-55,$Pos[1]-60,BitOR($WS_POPUP,$WS_BORDER)) ; Create GUI GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI") $MuteButton = GuiCtrlCreateButton("Mute", 20, 5, 80, 100, $BS_BITMAP) ; Create mute image/button GUICtrlSetImage($MuteButton, "UnMuted.bmp", 1) ; Set current mute status to un-muted GUICtrlSetOnEvent($MuteButton, "Mute") ; Create action for mute button $HotkeyCheckBox = GUICtrlCreateCheckbox("HotKey CheckBox", 100, 70, -1, -1) ; Create hotkey check box GUICtrlSetOnEvent($HotkeyCheckBox, "Hotkeys") ; Create action for hotkey check box GUISetBkColor(0x000000) ; Set GUI background to black WinSetTrans($gui,"",60) ; Set transparency for GUI GUISetState() ; Display GUI $a = _CreateLevelMeter(0,0,False,20,5,30,0xFFFFFF,0x0000FF) ; Create volume meter EndIf If $status2 >= 2 Then GuiSetState(@SW_HIDE, $Gui) $status2 = 0 EndIf EndFunc ; End GUI Display Func Mute() ; Begin mute function If $Mute = 1 Then ; Detect if volume is muted, if it is, unmute. GUICtrlSetImage($MuteButton, "UnMuted.bmp", 1) ; Display un-muted volume image $Mute = 0 ; Set mute to 0 ElseIf $Mute = 0 Then ; Detect if volume is muted, if it isn't, mute. GUICtrlSetImage($MuteButton, "MuteImage.bmp", 1) ; Display muted volume image $Mute = 1 ; Set mute to 1 EndIf ; End mute detection Send("{VOLUME_MUTE}") ; Toggle mute/un-mute EndFunc ; End mute function Func VolumeControl() ; Begin volume control If $status >= 2 Then ; Detect if volume control has been enabled. $status = 0 ; If it has, reset it to allow for stop/go EndIf ; End If $status += 1 ; Set status to 1 to ackknowledge volume control is being used While $Status < 2 ; Begin volume meter tracking $WatchMousePos = MouseGetPos() ; Get current mouse pos to compare to previous mouse pos. If $Amount < 3 Then ; Detect if meter is at its lowest point to assure it doesn't exceed its array $Amount += 1.6 ; If it is at lowest, keep at a functionable level EndIf ; End If for lowest point If $Amount > 98 Then ; Detect if meter is at its highest point to assure it doesn't exceed its array $Amount -= 2.5 ; If it is at highest, keep at a functionable level EndIf ; End If for highest point If $WatchMousePos[1] > $Pos[1] Then ; Detect movement for controlling volume down $Pos[1] = $WatchMousePos[1] ; Set WatchMousePos[1] to pre-existing y for next movement detection $Amount -= 1.4 ; Lower the amount in order to display correct meter adjustments $s1=$Amount ; Adjust meter _ShowLevelMeter($s1,$a) ; Display meter Send("{VOLUME_DOWN}") ; Lower volume accordingly EndIf ; End If for mouse down movemenet If $WatchMousePos[1] < $Pos[1] Then ; Detect movement for controlling volume up $Pos[1] = $WatchMousePos[1] ; Set WatchMousePos[1] to pre-existing y for next movement detection $Amount += 1.8 ; Raise the amount in order to display correct meter adjustments $s1=$Amount ; Adjust meter _ShowLevelMeter($s1,$a) ; Display meter Send("{VOLUME_UP}") ; Raise volume accordingly EndIf ; End If for mouse up movemenet WEnd ; End while for active volume control EndFunc ; End VolumeControl function Func HotKeys() $iTunesApp = ObjCreate("iTunes.Application") GUICtrlSetState ($HotkeyCheckBox, $GUI_UNCHECKED) $HotKeyGUIOpen = 1 $HotKeyGUI = GUICreate("Hotkeys", 200, 230,$Pos[0]-55,$Pos[1]-60,BitOR($WS_POPUP,$WS_BORDER)) $CreateTab = GUICtrlCreateTab(10, 10, 180, 210) $iTunesTab = GUICtrlCreateTabItem("iTunes") GuiCtrlCreateLabel("Modifier keys:", 60, 34) $iTunesWinModifierKey = GUICtrlCreateCheckbox("Win", 15, 48, -1, -1) $iTunesControlModifierKey = GUICtrlCreateCheckbox("Ctrl", 58, 48, -1, -1) $iTunesAltModifierKey = GUICtrlCreateCheckbox("Alt", 100, 48, -1, -1) $iTunesShiftModifierKey = GUICtrlCreateCheckbox("Shift", 140, 48, -1, -1) $iTunesPlaynPauseHotkeyList = GUICtrlCreateCombo("Play/Pause HotKey", 18, 78, 160,10) GUICtrlSetData(-1, $KeyList) $iTunesNextHotkeyList = GUICtrlCreateCombo("Next Song HotKey", 18, 105, 160,10) GUICtrlSetData(-1, $KeyList) $iTunesPreviousHotkeyList = GUICtrlCreateCombo("Previous Song HotKey", 18, 133, 160,10) GUICtrlSetData(-1, $KeyList) $AcceptiTunesHotKeysButton = GuiCtrlCreateButton("Submit", 75,160) GUICtrlSetOnEvent($AcceptiTunesHotKeysButton, "SubmitiTunesHotKeyInfo") GuiSetState() EndFunc Func SubmitiTunesHotKeyInfo() HotKeySet($Modifier & $iTunesPlaynPauseHotKey) HotKeySet($Modifier & $iTunesNextHotkey) HotKeySet($Modifier & $iTunesPreviousHotkey) $Modifier = "" $iTunesWinModifier = GUICtrlRead($iTunesWinModifierKey) If $iTunesWinModifier = $GUI_UNCHECKED Then Sleep(10) ElseIf $iTunesWinModifier = $GUI_CHECKED Then $Modifier = "#" EndIf $iTunesControlModifier = GUICtrlRead($iTunesControlModifierKey) If $iTunesControlModifier = $GUI_UNCHECKED Then Sleep(10) ElseIf $iTunesControlModifier = $GUI_CHECKED Then $Modifier = "^" EndIf $iTunesAltModifier = GUICtrlRead($iTunesAltModifierKey) If $iTunesAltModifier = $GUI_UNCHECKED Then Sleep(10) ElseIf $iTunesAltModifier = $GUI_CHECKED Then $Modifier = "!" EndIf $iTunesShiftModifier = GUICtrlRead($iTunesShiftModifierKey) If $iTunesShiftModifier = $GUI_UNCHECKED Then Sleep(10) ElseIf $iTunesShiftModifier = $GUI_CHECKED Then $Modifier = "+" EndIf $iTunesPlaynPauseHotKey = GUICtrlRead($iTunesPlaynPauseHotkeyList) $iTunesNextHotkey = GUICtrlRead($iTunesNextHotkeyList) $iTunesPreviousHotkey = GUICtrlRead($iTunesPreviousHotkeyList) $iTunesPlaynPauseHotKey = "{" & $iTunesPlaynPauseHotKey & "}" $iTunesNextHotkey = "{" & $iTunesNextHotkey & "}" $iTunesPreviousHotkey = "{" & $iTunesPreviousHotkey & "}" HotKeySet($Modifier & $iTunesPlaynPauseHotKey, "iTunesPlaynPause") HotKeySet($Modifier & $iTunesNextHotkey, "iTunesNext") HotKeySet($Modifier & $iTunesPreviousHotkey, "iTunesPrevious") MsgBox(0, "Test", "iTunes Hotkeys submitted..") GuiDelete($HotKeyGUI) GuiCtrlSetState($iTunesWinModifier, $GUI_UNCHECKED) GuiCtrlSetState($iTunesControlModifier, $GUI_UNCHECKED) GuiCtrlSetState($iTunesAltModifier, $GUI_UNCHECKED) GuiCtrlSetState($iTunesShiftModifier, $GUI_UNCHECKED) EndFunc Func iTunesPlaynPause() $iTunesApp.PlayPause EndFunc Func iTunesNext() $iTunesApp.NextTrack EndFunc Func iTunesPrevious() $iTunesApp.PreviousTrack EndFunc Func CloseGUI() If $HotKeyGUIOpen = 0 Then Exit EndIf If $HotKeyGUIOpen = 1 Then $HotKeyGUIOpen = 0 GuiDelete($HotKeyGUI) EndIf EndFuncAnd the included file, VolumeMeter by taietel, thanks again.expandcollapse popupFunc _CreateLevelMeter($iX=5, $iY=5, $bContinous=False, $iUnits=20, $iUnitHeight=5, $iUnitWidth=30, $lStartColour=0xFFFF00, $lEndColour=0xFF0000) Local $iUH, $arIndicator[$iUnits], $arColours[$iUnits] Local $arRet[$iUnits][3] If $bContinous = False Then $iUH = $iUnitHeight+1 Else $iUnitHeight+=1 $iUH = $iUnitHeight EndIf ;label to show some values (optional) $hLblValue = GUICtrlCreateLabel("", $iX, $iY+$iUH*$iUnits+$iUH+5, $iUnitWidth, 18,$SS_CENTER) GUICtrlSetColor(-1,0xEFEFEF) $Ri = Mod($lStartColour,256) $Gi = BitAND($lStartColour/256,255) $Bi = BitAND($lStartColour/65536,255) $Rf = Mod($lEndColour,256) $Gf = BitAND($lEndColour/256,255) $Bf = BitAND($lEndColour/65536,255) $Rs = Abs($Ri - $Rf)/$iUnits $Gs = Abs($Gi - $Gf)/$iUnits $Bs = Abs($Bi - $Bf)/$iUnits If $Rf < $Ri Then $Rs = -$Rs If $Gf < $Gi Then $Gs = -$Gs If $Bf < $Bi Then $Bs = -$Bs For $i=0 To $iUnits-1 $Rf = $Ri + $Rs * $i $Gf = $Gi + $Gs * $i $Bf = $Bi + $Bs * $i $arColours[$i]="0x"&Hex($Bf,2) & Hex($Gf,2) & Hex($Rf,2) Next For $i=0 To $iUnits-1 $arIndicator[$i] = GUICtrlCreateLabel("", $iX, ($iY+$iUH*$iUnits)-$iUH*$i, $iUnitWidth, $iUnitHeight) $arRet[$i][0]=$arIndicator[$i] $arRet[$i][1]=$arColours[$i] $arRet[$i][2]=$iUnits Next Return $arRet EndFunc Func _ShowLevelMeter($Signal,ByRef $avArray) Local $iUnitsColoured Local $m = Mod($Signal, $avArray[0][2]) Switch $m Case 0 $iUnitsColoured=($Signal-$m)*$avArray[0][2]/100 Case Else $iUnitsColoured=($Signal-$m)*$avArray[0][2]/100 + 1 EndSwitch For $i=0 To $iUnitsColoured-1 GUICtrlSetBkColor($avArray[$i][0], $avArray[$i][1]) Next For $j=UBound($avArray)-1 To $iUnitsColoured Step -1 GUICtrlSetBkColor($avArray[$j][0], $GUI_BKCOLOR_TRANSPARENT) Next EndFuncSource Code:VolumeControl.au3VolumeMeter:VolumeMeter.au3Un-muted image:Muted image: Edited February 14, 2011 by Damein Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic
Damein Posted February 9, 2011 Author Posted February 9, 2011 Updated first post, I realized I had no way of hiding the GUI after you open it, so if you used it for hotkeys you would be forced to keep the GUI open the whole time. I fixed that and I uploaded the images for the mute/un-mute button so it would look cleaner. Leave some comments on what you think Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic
Damein Posted February 14, 2011 Author Posted February 14, 2011 Edited the code block because I forgot to remove a MsgBox that I had previously used to test a function, just some script clean-up. Almost 20 downloads and no responses? I r sad! Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic
AppTux Posted February 14, 2011 Posted February 14, 2011 (edited) I get this error: >Running AU3Check (1.54.19.0) from:D:\AutoIt3 E:\AutoIt\VolumeControl.au3(159,22) : WARNING: $iTunesApp: possibly used before declaration. $iTunesApp.PlayPause ~~~~~~~~~~~~~~~~~~~~^ E:\AutoIt\VolumeControl.au3(159,22) : ERROR: $iTunesApp: undeclared global variable. $iTunesApp.PlayPause ~~~~~~~~~~~~~~~~~~~~^ E:\AutoIt\VolumeControl.au3 - 1 error(s), 1 warning(s) !>21:18:38 AU3Check ended.rc:2 Well, I just continue, but your meter is a bit too big, so it goes over your meter. Just make the meter smaller: $a = _CreateLevelMeter(0,0,False,20,5,20,0xFFFFFF,0x0000FF) ; Create volume meter And I prefer a less transparent window, to transparency of 200... Edit: I wrote that the button was too big, it was the meter Edited February 14, 2011 by AppTux PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.
AppTux Posted February 14, 2011 Posted February 14, 2011 Because it doesn't recognize or whatever iTunes, I can't use the next/previous/play hotkeys without getting a error.... PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.
Damein Posted February 15, 2011 Author Posted February 15, 2011 Hmm, not sure why you are getting this error. Did you by chance remove this section of code? $iTunesApp = ObjCreate("iTunes.Application") Because it has to be there to allow control of iTunes. Try moving this section to the top of the code, just below the Global section. Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic
AppTux Posted February 15, 2011 Posted February 15, 2011 Hmm, not sure why you are getting this error. Did you by chance remove this section of code? $iTunesApp = ObjCreate("iTunes.Application") Because it has to be there to allow control of iTunes. Try moving this section to the top of the code, just below the Global section. I put it by Global, and I don't get the error anymore. And now the hotkeys are working!!! Now I like it more because a minimized iTunes haven't hotkeys. PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.
AppTux Posted February 15, 2011 Posted February 15, 2011 I was playing around with your script and made a bit smaller version: Just replace the ShowGUI() function. You also have to replace the images with the new ones I made: Images.zip Func ShowGUI() ; Begin GUI display $status2 += 1 If $status2 < 2 Then GUIDelete($Gui) ; Delete existing GUI's $Pos = MouseGetPos() ; Get current mouse position for placement of GUI $Gui = GUICreate("Volume Control", 90, 30, $Pos[0] - 55, $Pos[1] - 60, BitOR($WS_POPUP, $WS_BORDER)) ; Create GUI GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI") $MuteButton = GUICtrlCreateButton("Mute", 20, 2, 20, 25, $BS_BITMAP) ; Create mute image/button GUICtrlSetImage($MuteButton, "UnMuted.bmp", 1) ; Set current mute status to un-muted GUICtrlSetOnEvent($MuteButton, "Mute") ; Create action for mute button $HotkeyBtn = GUICtrlCreateButton("Hotkeys", 40, 2, -1, -1) ; Create hotkey check box GUICtrlSetOnEvent($HotkeyBtn, "Hotkeys") ; Create action for hotkey check box GUISetBkColor(0xa5a5a5) ; Set GUI background to black GUISetState() ; Display GUI $a = _CreateLevelMeter(0, 0, False, 15, 1, 20, 0x00FF00, 0xFF0000) ; Create volume meter EndIf If $status2 >= 2 Then GUISetState(@SW_HIDE, $Gui) $status2 = 0 EndIf EndFunc ;==>ShowGUI And I found a bug: If you press Alt+v when the window isn't opened yet you get this error: >Running:(3.3.6.1):D:\AutoIt3\autoit3.exe "E:\AutoIt\VolumeControl.au3" E:\AutoIt\VolumeControl.au3 (70) : ==> Subscript used with non-Array variable.: If $WatchMousePos[1] > $Pos[1] Then If $WatchMousePos[1] > $Pos^ ERROR ->18:57:46 AutoIT3.exe ended.rc:1 >Exit code: 1 Time: 5.698 PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now