Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #SingleInstance Force
- #NoEnv
- SetBatchlines -1
- Sendmode Input
- key := "RAlt"
- running := minSpeed := startValue := hideState := 0
- ; register for rawinput
- _size := 8 + A_PtrSize
- RIDEV_INPUTSINK := 0x00000100
- VarSetCapacity(RAWINPUTDEVICE, _size)
- NumPut(1, RAWINPUTDEVICE, 0, "UShort")
- NumPut(2, RAWINPUTDEVICE, 2, "UShort")
- NumPut(RIDEV_INPUTSINK, RAWINPUTDEVICE, 4, "Uint")
- Gui +hwndhwnd
- NumPut(hwnd, RAWINPUTDEVICE, 8, "Uint")
- DllCall("RegisterRawInputDevices", "Ptr", &RAWINPUTDEVICE, "UInt", 1, "UInt", _size )
- OnMessage(0x00FF, "RawInputCallback")
- ; store the existing scrollline setting so it can be restored on exit
- SetScrollLines()
- OnExit("RestoreScrollLines")
- HotKey, % key " Up", revealCursor_stopScroll
- Return
- SetScrollLines(value := 3) {
- global startValue
- DllCall("SystemParametersInfo", UInt, 0x0068, UInt, 0, UIntP, CurrentScrolls, UInt, 0)
- if !startValue
- startValue := CurrentScrolls
- if CurrentScrolls != value
- DllCall("SystemParametersInfo", UInt, 0x0069, UInt, value, UIntP, 0, UInt, 0)
- }
- RestoreScrollLines() {
- global startValue
- DllCall("SystemParametersInfo", UInt, 0x0069, UInt, startValue, UIntP, 0, UInt, 0)
- }
- ; Get mouse movement rawinput and fire a scroll function with x and y deltas
- RawInputCallback(wParam, lParam) {
- Critical
- static DeviceSize := 2 * A_PtrSize
- , Size := 0
- , pSize:= 8 + 2 * A_PtrSize
- , delta:= {x: 20 + (A_PtrSize * 2), y: 24 + (A_PtrSize * 2)}
- , RawInput
- VarSetCapacity(header, pcbSize, 0)
- DllCall("GetRawInputData", "UPtr", lParam, "uint", 0x10000005, "UPtr", &header, "Uint*", pcbSize, "Uint", pSize)
- VarSetCapacity(RawInput, Size)
- DllCall("GetRawInputData", "UInt", lParam, "UInt", 0x10000003, "Ptr", &RawInput, "UInt*", Size, "UInt", pSize)
- x := NumGet(&RawInput, delta.x, "Int"), y := NumGet(&RawInput, delta.y, "Int")
- if (y != 0)
- Scroll(x, y)
- }
- ; get the velocity of input and start a timer to repeat scrolling up or down by mouse speed & direction (move at least 45 degrees vertically and at least 1 pixel / ms)
- Scroll(x, y) {
- static minThreshold := 1, angleThreshold := atan(1), velocity := 0.01, last_direction := 0
- global hideState, key, minSpeed, running
- if (y > 0 && last_direction != -1){
- last_direction := -1
- minSpeed := 0
- velocity := 0.01
- }
- else if (y < 0 && last_direction != 1) {
- last_direction := 1
- minSpeed := 0
- velocity := 0.01
- }
- velocity := 0.5 * ((sqrt(x*x + y*y) / GetTime()) - velocity) + velocity
- angle := x ? atan(abs(y / x)) : angleThreshold * 2
- if (angle < angleThreshold || velocity < minThreshold)
- return
- if GetKeyState(key, "P") {
- if !hideState {
- showMouse(0)
- hideState := 1
- }
- num_lines := (velocity > 12) ? "6" : (velocity > 10) ? "3" : (velocity > 6) ? "2" : "1"
- if (num_lines > minSpeed)
- minSpeed := num_lines
- centreCursor(), SetScrollLines(minSpeed)
- if (y > 0 && running != -1) {
- running := -1
- SetTimer RepeatDown, Off
- SetTimer RepeatUp, 0
- }
- else if (y < 0 && running != 1) {
- running := 1
- SetTimer RepeatUp, Off
- SetTimer RepeatDown, 0
- }
- }
- }
- GetTime() {
- static last := 0, freq := 0, scaler_ms := 0
- if (!freq) {
- DllCall("QueryPerformanceFrequency", "Int64P", freq)
- scaler_ms := 1000 / freq
- }
- DllCall("QueryPerformanceCounter","Int64P", current)
- elapsed := (current - last) * scaler_ms
- last := current
- return elapsed
- }
- RepeatUp() {
- Send {WheelUp}
- }
- RepeatDown(){
- Send {WheelDown}
- }
- ; hide and centre the mouse cursor while scrolling
- showMouse(state) {
- static BlankCursor := "", CleanUp := {base: {__Delete: "showMouse"}}
- static CursorList := "32512, 32513, 32514, 32515, 32516, 32640, 32641"
- . ",32642, 32643, 32644, 32645, 32646, 32648, 32649, 32650, 32651"
- local ANDmask, XORmask, CursorHandle
- if state
- return, DllCall("SystemParametersInfo", "UInt", 0x57, "UInt", 0, "Ptr", 0, "UInt", 0)
- if !BlankCursor {
- VarSetCapacity(ANDmask, 32 * 4, 0xFF)
- VarSetCapacity(XORmask, 32 * 4, 0x00)
- BlankCursor := DllCall("CreateCursor", "Ptr", 0 , "Int", 0, "Int", 0, "Int", 32, "Int", 32, "Ptr", &ANDmask, "Ptr", &XORmask, "Ptr")
- }
- loop, Parse, CursorList, `,, % A_Space
- {
- CursorHandle := DllCall("CopyImage", "Ptr", BlankCursor, "UInt", 2, "Int", 0, "Int", 0, "UInt", 0, "Ptr")
- DllCall("SetSystemCursor", "Ptr", CursorHandle, "UInt", A_Loopfield)
- }
- }
- revealCursor_stopScroll() {
- global hideState, minSpeed, running
- running := minSpeed := 0
- if hideState {
- showMouse(1)
- hideState := 0
- }
- SetTimer RepeatUp, Off
- SetTimer RepeatDown, Off
- }
- centreCursor() {
- static centerX := A_ScreenWidth / 2, centerY := A_ScreenHeight / 2
- DllCall("SetCursorPos", "Int", centerX, "Int", centerY)
- }
- ^Esc::ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement