Advertisement
DuskDegree9667

iTunes Dual-Layer AHK Script for Macro Mouse (AHK_iTunes.ahk)

Jun 25th, 2025 (edited)
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Persistent
  2. SetTitleMatchMode, 2  ; Allow partial matches for window titles.
  3. DetectHiddenWindows, On
  4. CoordMode, Mouse, Screen
  5.  
  6. Layer2 := false
  7.  
  8. hotkey1::
  9.     if (!Layer2) {
  10.         Send, ^{[} ; Previous Page
  11.         KeyWait, F8
  12.     } else {
  13.         Send, ^{[} ; Previous Page
  14.         KeyWait, F8
  15.     }
  16. Return
  17.  
  18. hotkey2::
  19.     if (!Layer2) {
  20.         Send, ^{]} ; Next Page
  21.         KeyWait, F9
  22.     } else {
  23.         Send, ^{]} ; Next Page
  24.         KeyWait, F9
  25.     }
  26. Return
  27.  
  28. hotkey3::
  29.     Layer2 := !Layer2 ; Layer Switch
  30.     if (Layer2) {
  31.         SetTimer, UpdateTooltip2, 50
  32.         KeyWait, F10
  33.     } else {
  34.         SetTimer, UpdateTooltip2, Off
  35.         SetTimer, UpdateTooltip1, 50
  36.         KeyWait, F10
  37.         SetTimer, RemoveTooltip, -1000
  38.     }
  39.     Send, {Esc} ; Escape the Application key menu
  40. Return
  41.  
  42. UpdateTooltip2:
  43.    if (Layer2) {
  44.         MouseGetPos, MouseX, MouseY
  45.         Tooltip, Layer 2 is active, MouseX + 15, MouseY + 15
  46.     }
  47. Return
  48.  
  49. UpdateTooltip1:
  50.    MouseGetPos, MouseX, MouseY
  51.     Tooltip, Layer 1 is active, MouseX + 15, MouseY + 15
  52. Return
  53.  
  54. RemoveTooltip:
  55.    SetTimer, UpdateTooltip1, Off
  56.     Tooltip
  57. Return
  58.  
  59. hotkey4::
  60.     if (!Layer2) {
  61.         Send, ^i ; Get Info Panel
  62.         KeyWait, F11
  63.     } else {
  64.         Send, ^i ; Get Info Panel
  65.         KeyWait, F11
  66.     }
  67. Return
  68.  
  69. hotkey5::
  70.     if (!Layer2) {
  71.         Return ; LAYER1 ACTION
  72.     } else {
  73.         Return ; LAYER2 ACTION
  74.     }
  75. Return
  76.  
  77. hotkey6::
  78.     if (!Layer2) {
  79.         Send, ^c ; Copy
  80.         KeyWait, F13
  81.     } else {
  82.         Send, ^c ; Copy
  83.         KeyWait, F13
  84.     }
  85. Return
  86.  
  87. hotkey7::
  88.     if (!Layer2) {
  89.         Send, ^{Right} ; Next Track
  90.         KeyWait, F14
  91.     } else {
  92.         Send, {Home} ; Go to Top of List
  93.         KeyWait, F14
  94.     }
  95. Return
  96.  
  97. hotkey8::
  98.     if (!Layer2) {
  99.         Send, ^x ; Cut
  100.         KeyWait, F15
  101.     } else {
  102.         Send, ^x ; Cut
  103.         KeyWait, F15
  104.     }
  105. Return
  106.  
  107. hotkey9::
  108.     if (!Layer2) {
  109.         Send, ^v ; Paste
  110.         KeyWait, F16
  111.     } else {
  112.         Send, ^v ; Paste
  113.         KeyWait, F16
  114.     }
  115. Return
  116.  
  117. hotkey10::
  118.     if (!Layer2) {
  119.         Send, ^+{Right} ; Next Chapter
  120.         KeyWait, F17
  121.     } else {
  122.         Send, {PgUp} ; Scroll List Up by One Screenful
  123.         KeyWait, F17
  124.     }
  125. Return
  126.  
  127. hotkey11::
  128.     if (!Layer2) {
  129.         Send, {Delete} ; Delete Selected Item
  130.         KeyWait, F18
  131.     } else {
  132.         Send, {LAlt} ; Show Duplicates
  133.         Sleep, 100
  134.         Send, f
  135.         Sleep, 100
  136.         Send, b
  137.         Sleep, 100
  138.         Send, d
  139.         Sleep, 10
  140.         KeyWait, F18
  141.     }
  142. Return
  143.  
  144. hotkey12::
  145.     if (!Layer2) {
  146.         Send, {AppsKey}
  147.         Sleep, 100
  148.         Send, t ; Show Song in Playlist…
  149.         Sleep, 10
  150.         KeyWait, F19
  151.     } else {
  152.         Send, {AppsKey}
  153.         Sleep, 100
  154.         Send, b ; Show Song's in Album View
  155.         Sleep, 10
  156.         KeyWait, F19
  157.     }
  158. Return
  159.  
  160. hotkey13::
  161.     if (!Layer2) {
  162.         Send, ^+{Left} ; Previous Chapter
  163.         KeyWait, F20
  164.     } else {
  165.         Send, {PgDn} ; Scroll List Down by One Screenful
  166.         KeyWait, F20
  167.     }
  168. Return
  169.  
  170. hotkey14::
  171.     if (!Layer2) {
  172.         Send, {AppsKey}
  173.         Sleep, 100
  174.         Send, d ; Add Song to Playlist…
  175.         Sleep, 10
  176.         KeyWait, F21
  177.     } else {
  178.         Send, {LAlt} ; Hide Duplicates
  179.         Sleep, 100
  180.         Send, f
  181.         Sleep, 100
  182.         Send, b
  183.         Sleep, 100
  184.         Send, h
  185.         Sleep, 10
  186.         KeyWait, F21
  187.     }
  188. Return
  189.  
  190. hotkey15::
  191.     if (!Layer2) {
  192.         Send, {Enter}
  193.         KeyWait, F22
  194.     } else {
  195.         Send, {Enter}
  196.         KeyWait, F22
  197.     }
  198. Return
  199.  
  200. hotkey16::
  201.     if (!Layer2) {
  202.         Send, ^{Left} ; Previous Track
  203.         KeyWait, F23
  204.     } else {
  205.         Send, {End} ; Go to Bottom of List
  206.         KeyWait, F23
  207.     }
  208. Return
  209.  
  210. hotkey17::
  211.     if (!Layer2) {
  212.         Send, ^l ; Jump to Current Track
  213.         KeyWait, F24
  214.     } else {
  215.         Send, ^l ; Jump to Current Track
  216.         KeyWait, F24
  217.     }
  218. Return
  219.  
  220. ; Infinite scroll function
  221. #MaxHotkeysPerInterval 500
  222. #InstallKeybdHook
  223. #InstallMouseHook
  224.  
  225. *WheelUp::Scroll(-1)
  226. *WheelDown::Scroll(1)
  227.  
  228. Scroll(Direction) {
  229.     static scrollCount := 0, level := 1, maxLevel := 15, timeout := 350, levelTickCount := 0
  230.         , startingShiftState := 0, scrollingState := 0, flick := 0, wheelDir := ""
  231.  
  232.     if (level < maxLevel && ++scrollCount >= 4) { ; Change level when scrolling 4 times in a row, check for flick by detecting if it was scrolled 4 times within 60 ms.
  233.         flick := (A_TickCount - levelTickCount < 60)
  234.         levelTickCount := A_TickCount
  235.         level++
  236.         scrollCount := 1
  237.     }
  238.  
  239.     wheelDir := (Direction = -1 ? "WheelUp" : "WheelDown")
  240.  
  241.     if (A_PriorHotkey = A_ThisHotkey && A_TimeSincePriorHotkey < timeout && level > 1) {
  242.         Send, {Blind}{%wheelDir% %level%} ; Scroll faster when scrolling consecutively in a single direction.
  243.         if (flick) {
  244.             startingShiftState := GetKeyState("Shift", "P")
  245.             scrollingState := 1
  246.             SetTimer, AutoScroll, 30
  247.         }
  248.     } else {
  249.         if (scrollingState)
  250.             scrollingState := 0
  251.         else
  252.             Send, {Blind}{%wheelDir%}
  253.         level := 1
  254.     }
  255.     return
  256.  
  257.     AutoScroll:
  258.        if (level = 1 ; Stop auto-scroll if…
  259.         || GetKeyState("Shift", "P") != startingShiftState
  260.         || !scrollingState
  261.         || A_PriorHotKey != A_ThisHotkey) {
  262.             scrollingState := 0
  263.             SetTimer, AutoScroll, Off
  264.         } else {
  265.             Send, {Blind}{%wheelDir% %level%}
  266.         }
  267.     return
  268. }
Tags: itunes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement