08wckster08

Untitled

May 6th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Windows 8 inspired GDIP volume OSD
  2. ;   http://www.autohotkey.com/board/topic/94248-windows-8-inspired-gdip-volume-osd/
  3. ;Made by Rijul Ahuja
  4. ;       rijul13.wordpress.com
  5. ;Thanks to tic (Tariq Porter) for his GDI+ Library and rseding91 for making it all compatible
  6. ;   http://www.autohotkey.com/forum/viewtopic.php?t=32238
  7. ;Get the GDIP_all.ahk from here and place it in <location of Autohotkey.exe>\lib\GDIP.ahk
  8. ;   http://www.autohotkey.net/~Rseding91/Gdip%20All/Gdip_All.ahk
  9. ;Uncomment if GDIP.ahk is not in your library, put it in the script directory.
  10. ;#Include GDIP.ahk
  11. ;===========================Configuration=========================================
  12.  
  13. #Include C:\Users\08Wckster08\Dropbox\Lib\GDIP.ahk
  14. #Include C:\Users\08Wckster08\Dropbox\Lib\VA.ahk
  15. Start:
  16. ;Leave any hotkey blank if you like
  17. VolUpHotkey:="!e"
  18. VolDownHotkey:="!q"
  19. VolMuteHotkey:="!w"
  20.  
  21. ;Position of OSD
  22. PosOSD:="BottomLeft"  ;TopLeft / TopRight / TopCenter / BottomLeft / BottomCenter / BottomRight
  23.                     ;case insensitive, Center can be written as centre
  24.  
  25. ;Change volume display font
  26. Font:="Arial"
  27.  
  28. ;Change colour of volume level (ARGB)
  29. VolColour:="0xFF00FF00"
  30.  
  31. ;Should OSD animate on leave? (experimental)
  32. AnimateWindow:=true
  33.  
  34. ;Set to true if OSD should not disappear when mouse is over it.
  35. ShouldMouse:=true
  36.  
  37. ;==========================Config complete========================================
  38. ;Do not edit anything below this unless you know what you are doing
  39.  
  40. #SingleInstance Force
  41. #NoEnv
  42. GetPos(PosOSD)
  43. SetWorkingDir, % A_ScriptDir
  44. SetHotkeys()
  45. If !pToken := Gdip_Startup()
  46. {
  47.     MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have GDI+ on your system.
  48.     ExitApp
  49. }
  50. If !Gdip_FontFamilyCreate(Font)
  51. {
  52.    MsgBox, 48, Font error!, The font you have specified does not exist on the system
  53.    ExitApp
  54. }
  55. Gui, VolOSD: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
  56. Gui, VolOSD: Show, NA Center Hide, % SubStr(A_ScriptName,1,-4)
  57. OnExit, Exit
  58. OnMessage(0x201,"WM_LButtonDown")
  59. ;The smallest auto exec of my scripts is complete!
  60. return
  61.  
  62. WM_LButtonDown(wParam,lParam)
  63. {
  64.     X := lParam & 0xFFFF, Y := lParam >> 16
  65.     If ((X<19) or (X>29)) and (Y<15)
  66.         {}
  67.     else if (Y<115)
  68.         {
  69.         While(GetKeyState("LButton","P"))
  70.             {
  71.             MouseGetPos, , Y
  72.             Volume:=115-Y
  73.             SoundSet, % Volume
  74.             StartOSD()
  75.             }
  76.         }
  77.     else if (Y>=125) and (Y<=140) and (X>=18) and (X<=32)
  78.         {
  79.         SoundSet, +1, , Mute
  80.         StartOSD()
  81.         }
  82.     return 0
  83. }
  84.  
  85. SetHotkeys()
  86. {
  87.     global VolUpHotkey, VolDownHotkey, VolMuteHotkey
  88.     If VolUpHotkey
  89.         Hotkey, % VolUpHotkey, VolUpLabel
  90.     If VolDownHotkey
  91.         Hotkey, % VolDownHotkey, VolDownLabel
  92.     If VolMuteHotkey
  93.         Hotkey, % VolMuteHotkey, VolMuteLabel
  94.        
  95.     Hotkey, If, MouseIsOver("ahk_class Shell_TrayWnd")
  96.     Hotkey, WheelUp, VolUpLabel
  97.     Hotkey, WheelDown, VolDownLabel    
  98.     Hotkey, $Volume_Up, VolUpLabel
  99.     Hotkey, $Volume_Down, VolDownLabel
  100.     Hotkey, $Volume_Mute, VolMuteLabel
  101. }
  102.  
  103. #If MouseIsOver("ahk_class Shell_TrayWnd") or MouseIsOver("ahk_class Shell_SecondaryTrayWnd")
  104. #If
  105.  
  106. Exit:
  107. Gdip_Shutdown(pToken)
  108. ExitApp
  109.  
  110. VolDownLabel:
  111. VolMuteLabel:
  112. VolUpLabel:
  113. ToSend:=(A_ThisLabel="VolDownLabel") ? "{Volume_Down}" : ( (A_ThisLabel="VolMuteLabel") ? "{Volume_Mute}" : "{Volume_Up}" )
  114. Send % ToSend
  115. StartOSD()
  116. VarSetCapacity(ToSend,0)
  117. return
  118.  
  119. StartOSD()
  120. {
  121.     SoundGet, Volume
  122.     SoundGet, Muted, Master, Mute
  123.     Muted:=(Muted="On") ? 1 : 0
  124.     MakeSlider(round(Volume),Muted)
  125.     SetTimer, KillVolOSD, -2500
  126. }
  127.  
  128. KillVolOSD:
  129. return
  130.  
  131. AnimateWindow(hWnd,Duration,Flag)
  132.     {
  133.     Return DllCall("AnimateWindow","UInt",hWnd,"Int",Duration,"UInt",Flag)
  134.     }
  135.  
  136. MakeSlider(Volume,Muted)
  137. {
  138.     static hwnd1
  139.     global XPos,YPos,Font,VolColour
  140.     If !hwnd1
  141.         {
  142.         Gui, VolOSD:+Lastfound
  143.         hwnd1:=WinExist()
  144.         }    
  145.     hbm := CreateDIBSection(50,150)
  146.     hdc := CreateCompatibleDC()
  147.     obm := SelectObject(hdc, hbm)
  148.     G := Gdip_GraphicsFromHDC(hdc)
  149.     Gdip_SetSmoothingMode(G, 4)
  150.     pBrush := Gdip_BrushCreateSolid(0xD2000000)          ;background part
  151.     Gdip_FillRectangle(G, pBrush, 0, 0, 50, 150)
  152.     Gdip_DeleteBrush(pBrush)
  153.     If !Muted
  154.         pBrush := Gdip_BrushCreateSolid(VolColour)      ;Volume Level
  155.     else
  156.         pBrush:=Gdip_BrushCreateSolid(0xFF808080)
  157.     Gdip_FillRectangle(G, pBrush, 19, 15, 10, 100)
  158.     Gdip_DeleteBrush(pBrush)
  159.     pBrush := Gdip_BrushCreateSolid(0xFF606060)            ;slider background colour
  160.     Gdip_FillRectangle(G, pBrush, 19, 15, 10, 100-Volume)
  161.     Gdip_DeleteBrush(pBrush)
  162.     If !Mutedq
  163.         pBrush := Gdip_BrushCreateSolid(0xFFFFFFFF)
  164.     else
  165.         pBrush := Gdip_BrushCreateSolid(0xFFd3d3d3)
  166.     Gdip_FillRectangle(G,pBrush,19,110-(19*Volume)/20,10,5)
  167.     Gdip_DeleteBrush(pBrush)
  168.     If !Muted
  169.         GDIP_TextToGraphics(G,Volume,"x25 y125 cffffffff r4 s14 Center",Font)    ;volume text
  170.     else
  171.         GDIP_TextToGraphics(G,"X","x25 y125 cffffffff r4 s14 Bold Center",Font)    ;volume text
  172.     UpdateLayeredWindow(hwnd1, hdc, XPos, YPos,50,150)
  173.     Gui, VolOSD:Show, NA
  174.     SelectObject(hdc, obm)
  175.     DeleteObject(hbm)
  176.     DeleteDC(hdc)
  177.     Gdip_DeleteGraphics(G)
  178. }
  179.  
  180. MouseIsOver(WinTitle)
  181.     {
  182.         MouseGetPos,,, Win
  183.         return WinExist(WinTitle . " ahk_id " . Win)
  184.     }
  185.    
  186. GetPos(ByRef Var)
  187. {
  188.     Global XPos,YPos
  189.     Found:=false
  190.     HayStack:="topleft,topcenter,topright,bottomleft,bottomright,bottomcenter"
  191.     ;Ensure position is correct.
  192.     Loop, Parse, HayStack, `,
  193.         If (RegExMatch(Var,"i)" . A_LoopField)=1)
  194.         {
  195.             Found:=true
  196.             break
  197.         }
  198.     If !Found
  199.     {
  200.         MsgBox, 8208, % SubStr(A_ScriptName,1,-4), Error! Incorrect position of OSD.
  201.         ExitApp
  202.     }
  203.    
  204.     If Instr(Var,"Top")
  205.         YPos:=70
  206.     else
  207.         YPos:=A_ScreenHeight-455
  208.    
  209.     If InStr(Var,"Left")
  210.         XPos:=1930
  211.     else if InStr(Var,"Center") or InStr(Var,"Centre")
  212.         XPos:=(A_ScreenWidth/2)-55
  213.     else
  214.         XPos:=A_ScreenWidth-55
  215.     VarSetCapacity(Var,0)       ;free memory
  216. }
  217.  
  218. F12::
  219. SwapAudioDevice("Speakers (High Definition Audio Device)", "Speakers (Logitech G430 Gaming Headset)")
  220.  
  221. SwapAudioDevice(device_A, device_B)
  222. {
  223.     ; Get device IDs.
  224.     A := VA_GetDevice(device_A), VA_IMMDevice_GetId(A, A_id)
  225.     B := VA_GetDevice(device_B), VA_IMMDevice_GetId(B, B_id)
  226.     if A && B
  227.     {
  228.         ; Get ID of default playback device.
  229.         default := VA_GetDevice("playback")
  230.         VA_IMMDevice_GetId(default, default_id)
  231.         ObjRelease(default)
  232.        
  233.         ; If device A is default, set device B; otherwise set device A.
  234.         VA_SetDefaultEndpoint(default_id == A_id ? B : A, 0)
  235.     }
  236.     ObjRelease(B)
  237.     ObjRelease(A)
  238.     if !(A && B)
  239.         throw Exception("Unknown audio device", -1, A ? device_B : device_A)
  240. }
  241. goto, Start
  242. Return
Add Comment
Please, Sign In to add comment