Autohotkey v1 script to block mouse scrolling on video sites.

Works with Brave Browser which is a Chromium based browser.

https://www.autohotkey.com/download/1.1/AutoHotkey_1.1.37.02_setup.exe

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Menu, Tray, Icon, yt.ico
; --- Configuration Area ---
#SingleInstance Force
SetTitleMatchMode, 2

ScrollLockActive := 1
BlockedURLPatterns := ["youtube.com/watch?v="
, "twitch.tv/"
, "netflix.com/watch"]

Pause::
ScrollLockActive := !ScrollLockActive
TrayTip, Scroll Lock, % "Site Lock: " . (ScrollLockActive ? "ON" : "OFF"), 2
return

#If (ScrollLockActive && IsOverBraveAndBlocked(BlockedURLPatterns))
WheelUp::return
WheelDown::return
#If

IsOverBraveAndBlocked(URLArray) {
MouseGetPos,,, WindowIDUnderMouse

WinGet, processName, ProcessName, ahk_id %WindowIDUnderMouse%
if (processName != "brave.exe") {
return false
}

currentURL := GetURL2("ahk_id " . WindowIDUnderMouse)
for index, pattern in URLArray {
if InStr(currentURL, pattern)
return true
}
return false
}

GetURL2(wTitle*) {
if !(wId := WinExist(wTitle*))
return
IUIAutomation := ComObjCreate("{ff48dba4-60ef-4201-aa87-54103eef594e}", "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}")
DllCall(NumGet(NumGet(IUIAutomation+0)+6*A_PtrSize), "ptr", IUIAutomation, "ptr", wId, "ptr*", elementMain)
NumPut(addressbarStrPtr := DllCall("oleaut32\SysAllocString", "wstr", "Address and search bar", "ptr"),(VarSetCapacity(addressbar,8+2*A_PtrSize)+NumPut(8,addressbar,0,"short"))*0+&addressbar,8,"ptr")
DllCall("oleaut32\SysFreeString", "ptr", addressbarStrPtr)
if (A_PtrSize = 4)
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", 30005, "int64", NumGet(addressbar, 0, "int64"), "int64", NumGet(addressbar, 8, "int64"), "ptr*", addressbarCondition)
else
DllCall(NumGet(NumGet(IUIAutomation+0)+23*A_PtrSize), "ptr", IUIAutomation, "int", 30005, "ptr", &addressbar, "ptr*", addressbarCondition)
DllCall(NumGet(NumGet(elementMain+0)+5*A_PtrSize), "ptr", elementMain, "int", 0x4, "ptr", addressbarCondition, "ptr*", currentURLElement)
DllCall(NumGet(NumGet(currentURLElement+0)+10*A_PtrSize),"ptr",currentURLElement,"uint",30045,"ptr",(VarSetCapacity(currentURL,8+2*A_PtrSize)+NumPut(0,currentURL,0,"short")+NumPut(0,currentURL,8,"ptr"))*0+&currentURL)
ObjRelease(currentURLElement), ObjRelease(elementMain), ObjRelease(IUIAutomation)
return StrGet(NumGet(currentURL,8,"ptr"),"utf-16")
}

Leave a Comment

Auto