Skip to content

Instantly share code, notes, and snippets.

@Lorenzo501
Last active May 24, 2024 17:38
Show Gist options
  • Save Lorenzo501/33fc56ea7cc7cb7f773c2afee7626d71 to your computer and use it in GitHub Desktop.
Save Lorenzo501/33fc56ea7cc7cb7f773c2afee7626d71 to your computer and use it in GitHub Desktop.
#Requires AutoHotkey 2.0
#NoTrayIcon
#HotIf WinActive("ahk_exe uTorrent.exe")
~RButton::
{
static status := 0
if (!status)
OnClipboardChange(HandleClipChanged, status := 1)
HandleClipChanged(*)
{
static EVENT_OBJECT_NAMECHANGE := 0x800C
if (WinActive("ahk_exe uTorrent.exe"))
{
DllCall("SetWinEventHook",
"UInt", EVENT_OBJECT_NAMECHANGE,
"UInt", EVENT_OBJECT_NAMECHANGE,
"Ptr", 0,
"Ptr", CallbackCreate(HandleMediaPlayerEvent),
"UInt", 0,
"UInt", 0,
"UInt", 0)
Send("+{F10}p{Enter}{Tab}"), Run(A_ProgramFiles "\VideoLAN\VLC\vlc.exe --fullscreen " A_Clipboard)
}
OnClipboardChange(HandleClipChanged, status := 0)
HandleMediaPlayerEvent(hWinEventHook, event, hWnd, *)
{
static isBeingShownAfterTorrentStartsUnforced := false, WS_EX_LAYERED := 0x00080000
try
if (InStr(WinGetTitle(hWnd), "VLC media player",, -1) && !isBeingShownAfterTorrentStartsUnforced)
{
isBeingShownAfterTorrentStartsUnforced := true
WinSetTransparent(0, hWnd)
WinSetEnabled(false, "ahk_exe uTorrent.exe")
HotIf(MouseIsOverUTorrent)
Hotkey("LButton", ShowNetworkStreamMenu, "On")
Hotkey("RButton", ShowNetworkStreamMenu, "On")
DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
Sleep(-1) ; Discards queued events that might remain
WinExist(hWnd)
; Waiting until VLC is full screen
loop
if (WinGetExStyle() = WS_EX_LAYERED)
break
WinSetEnabled(true, "ahk_exe uTorrent.exe")
Hotkey("LButton", "Off")
Hotkey("RButton", "Off")
WinActivate("ahk_exe uTorrent.exe")
Send((ListViewGetContent("Count Focused", "SysListView322", WinExist("ahk_exe uTorrent.exe")) = 1 ? "{Down}{Up}" : "{Up}{Down}") "+{F10}s")
WinActivate(hWnd)
WinSetTransparent("Off", hWnd)
isBeingShownAfterTorrentStartsUnforced := false
}
MouseIsOver(winTitle, winText?, excludeTitle?, excludeText?) => (MouseGetPos(,, &winId), WinExist(winTitle " ahk_id " winId, winText?, excludeTitle?, excludeText?))
MouseIsOverUTorrent(*) => MouseIsOver("ahk_exe uTorrent.exe")
; This makes it possible to abort the network stream when the download speed is too low
ShowNetworkStreamMenu(*)
{
_menu := Menu()
_menu.Add("Abort Network Stream", AbortNetworkStream)
_menu.Show()
AbortNetworkStream(*)
{
WinClose("ahk_exe vlc.exe")
WinSetEnabled(true, "ahk_exe uTorrent.exe")
WinActivate("ahk_exe uTorrent.exe")
Reload() ; Stops HandleMediaPlayerEvent and removes dynamic hotkeys
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment