"Hand scrolling" any window - Autohotkey

Discussion in 'Software' started by vitor, Mar 9, 2010.

Thread Status:
Not open for further replies.
  1. vitor

    vitor Pen Pal - Newbie

    Messages:
    20
    Likes Received:
    2
    Trophy Points:
    6
    To those who might be interested, here's a Autohotkey script code for scrolling with the pen in any window. Something like "Grab and Drag" in Firefox but without touching the screen.
    This is useful for those with a two buttons pen (no wheel).

    How it works: press one keyboard button and drag your window (no pen click)!!! That's all.

    Scrolling trigger button is whatever you want, just edit the script, sensibility is also adjustable. Low CPU resources.

    Bellow, find the code for those who already have Autohotkey. The trigger key is set to "²". Just copy this code to a txt file and rename it with a *.ahk extension, launch it and you're done.

    Code:
    ; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
    ; semicolon, such as this one, are comments.  They are not executed.
    
    ; This script has a special filename and path because it is automatically
    ; launched when you run the program directly.  Also, any text file whose
    ; name ends in .ahk is associated with the program, which means that it
    ; can be launched simply by double-clicking it.  You can have as many .ahk
    ; files as you want, located in any folder.  You can also run more than
    ; one ahk file simultaneously and each will get its own tray icon.
    
    ;;
    ;; Emulate_Scrolling_Middle_Button.ahk
    ;; Author: Erik Elmore <erik@ironsavior.net>
    ;; Version: 1.1 (Aug 16, 2005)
    ;;
    ;; Enables you to use any key with cursor movement
    ;; to emulate a scrolling middle button.  While
    ;; the TriggerKey is held down, you may move the
    ;; mouse cursor up and down to send scroll wheel
    ;; events.  If the cursor does not move by the
    ;; time the TriggerKey is released, then a middle
    ;; button click is generated.  I wrote this for my
    ;; 4-button Logitech Marble Mouse (trackball), 
    ;; which has no middle button or scroll wheel.
    ;;
    
    ;; Configuration
    
    #NoTrayIcon
    
    ;; Higher numbers mean less sensitivity
    esmb_Threshold = 1
    ;; Delay 10*10ms, then put pointer back to original location
    esmb_delay = 10
    
    ;; This key/Button activates scrolling
    esmb_TriggerKey = ²
    
    ;; End of configuration
    
    #Persistent
    CoordMode, Mouse, Screen
    Hotkey, %esmb_TriggerKey%, esmb_TriggerKeyDown
    HotKey, %esmb_TriggerKey% Up, esmb_TriggerKeyUp
    esmb_KeyDown = n
    return
    
    esmb_TriggerKeyDown:
    esmb_Moved = n
    esmb_FirstIteration = y
    esmb_KeyDown = y
    MouseGetPos,, esmb_OldY
    MouseGetPos, esmb_OrigX, esmb_OrigY
    esmb_counter := 0
    SetTimer, esmb_CheckForScrollEventAndExecute, 10
    return
    
    esmb_TriggerKeyUp:
    esmb_KeyDown = n
    SetTimer, esmb_CheckForScrollEventAndExecute, Off
    ;; Send a middle-click if we did not scroll
    if esmb_Moved = n
        MouseClick, Middle
    return
    
    esmb_CheckForScrollEventAndExecute:
    if esmb_KeyDown = n
        return
    
    MouseGetPos,, esmb_NewY
    esmb_Distance := esmb_NewY - esmb_OldY
    if esmb_Distance
        esmb_Moved = y
    
    ;; Do not send clicks on the first iteration
    if esmb_FirstIteration = y
        esmb_FirstIteration = n
    else if esmb_Distance > %esmb_Threshold%
    {
        esmb_OldY := esmb_OldY + esmb_Threshold
        MouseClick, WheelDown
    }
    else if esmb_Distance < -%esmb_Threshold%
    {
        esmb_OldY := esmb_OldY - esmb_Threshold
        MouseClick, WheelUp
    }
    else
    {
        esmb_counter := esmb_counter + 1
        if( esmb_counter > esmb_delay)
        {
            esmb_counter := 0
            MouseMove,esmb_OrigX,esmb_OrigY
            MouseGetPos,, esmb_OldY
        }
    }
    return
    Please give credit to the author, not me!
     
    Last edited by a moderator: May 18, 2015
Thread Status:
Not open for further replies.

Share This Page