Skip to content

Instantly share code, notes, and snippets.

@kuntashov
Created November 9, 2025 13:50
Show Gist options
  • Select an option

  • Save kuntashov/3c659bd45baa5933b19d998db5803d2e to your computer and use it in GitHub Desktop.

Select an option

Save kuntashov/3c659bd45baa5933b19d998db5803d2e to your computer and use it in GitHub Desktop.
AHK-скрипт, который при удержании клавиши F13 на клавиатуре преобразует движения трекбола в скролл (в зависимости от направлениния).
; ===================================================================================
; AutoHotkey v2.0 Скрипт для режима прокрутки трекболом
;
; Описание:
; - Удерживайте `scrollKey` для активации режима прокрутки.
; - Движение трекбола преобразуется в вертикальную и горизонтальную прокрутку.
; ===================================================================================
#Requires AutoHotkey v2.0
#SingleInstance Force
; --- НАСТРОЙКИ ---
global scrollKey := "F13"
global scrollThreshold := 20
global scrollMultiplier := 1
; --- ГЛОБАЛЬНЫЕ ПЕРЕМЕННЫЕ ---
global isScrollingMode := false
global startX := 0, startY := 0
global accumulatorX := 0.0, accumulatorY := 0.0 ; Накопители смещения
; --- ОСНОВНАЯ ЛОГИКА ---
Hotkey("*" . scrollKey, ScrollKeyDown)
Hotkey("*" . scrollKey . " Up", ScrollKeyUp)
; Функция при НАЖАТИИ клавиши
ScrollKeyDown(*) {
global isScrollingMode, startX, startY, accumulatorX, accumulatorY
if isScrollingMode
return
isScrollingMode := true
MouseGetPos(&startX, &startY) ; Запоминаем точку "якоря"
accumulatorX := 0.0 ; Сбрасываем накопители
accumulatorY := 0.0
SetTimer(TrackMouseForScrolling, 10) ; Уменьшаем интервал для большей отзывчивости
}
; Функция при ОТПУСКАНИИ клавиши
ScrollKeyUp(*) {
global isScrollingMode
if !isScrollingMode
return
isScrollingMode := false
SetTimer(TrackMouseForScrolling, 0)
}
; Функция, отслеживающая движение мыши (логика с накопителем)
TrackMouseForScrolling() {
global isScrollingMode, startX, startY, scrollThreshold, scrollMultiplier, accumulatorX, accumulatorY
if !isScrollingMode
return
local currentX, currentY
MouseGetPos(&currentX, &currentY)
; 1. Добавляем новое смещение к накопителям
accumulatorX += currentX - startX
accumulatorY += currentY - startY
; 2. "Тратим" накопленное смещение на тики прокрутки
; Вертикальная прокрутка
while Abs(accumulatorY) >= scrollThreshold {
if (accumulatorY > 0) {
SendInput("{WheelDown " scrollMultiplier "}")
accumulatorY -= scrollThreshold
} else {
SendInput("{WheelUp " scrollMultiplier "}")
accumulatorY += scrollThreshold
}
}
; Горизонтальная прокрутка
while Abs(accumulatorX) >= scrollThreshold {
if (accumulatorX > 0) {
SendInput("{WheelRight " scrollMultiplier "}")
accumulatorX -= scrollThreshold
} else {
SendInput("{WheelLeft " scrollMultiplier "}")
accumulatorX += scrollThreshold
}
}
; 3. Принудительно возвращаем курсор в точку "якоря" КАЖДЫЙ РАЗ.
; Это не дает ему "убежать" между тиками таймера.
MouseMove(startX, startY, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment