Hi, thanks for this awsome script. I tried it for a day and works pretty good but made a similar script after a quick learn of the AutoHotkey syntax. I've added the possibility to scroll in both X and Y direction and also enabled the browser forward and backwards options as I was really missing those.
And one other thing that I've also added is so that the window where the mouse pointer currently are pointing to will gain focus upon clicking one of the designated keys.
Hope this will help someone ^^
Code:
;;
;; MarbleMagic 1.1
;; "Logitech Marble Mouse Optical" Configuration
;; Version: 1.1 (Jun 1, 2010)
;;
;; Created by Gawy, gawy.gawy@gmail.com
;;
;; Enables you to both scroll and use the back & forward
;; buttons for web browsing!
;;
;; Current configuration is:
;; Left small button = Back (in browser)
;; Left small button + right big = Forward (in browser) (Hold down the left small while pressing the right big)
;; Right small button = Enable scrolling with the trackball (Right small has to be held down)
;;
;; I wrote this simple code for the Logitech Marble Mouse as
;; it doesn't support scrolling by default and because the
;; logitech software sucks for customization.
;;
;; //Configuration
;; //Display a tray icon or not
;#NoTrayIcon
;; // Enable/disable
mm_EnableScrollX = y
mm_EnableScrollY = y
mm_EnableBrowserButtons = y
mm_EnableFocusGain = y ;; // Enable/disable windows focusing
;; //Lower = slower scrolling, 1.2 is pretty smooth
mm_ScrollAcceleration := 1.2
;; // Higher = slower scrolling (is dependent on the ScrollAcceleration!)
mm_VerticalScrollMultiplier := 1
;; // Higher = slower scrolling (is dependent on the ScrollAcceleration!)
mm_HorizontalScrollMultiplier := 20
;; // Higher = lower sense between X and Y scrolling, I would suggest moving it at 2 (will only take integers!)
mm_XScrollDivider := 2
;; // Timer
mm_TimerDelay := 10
;; // Triggers
;; //XButton2 = Right small, XButton1 = Left small, RButton = Right mouse button
mm_ScrollTrigger = XButton2
mm_BrowseBackwardsTrigger = XButton1
mm_BrowseForwardsTrigger = XButton1 & RButton
;; //End of configuration
#Persistent
CoordMode, Mouse, Screen
Hotkey, %mm_ScrollTrigger%, mm_ScrollTriggerDown
HotKey, %mm_ScrollTrigger% Up, mm_ScrollTriggerUp
if mm_EnableBrowserButtons = y
{
HotKey, %mm_BrowseForwardsTrigger%, mm_TriggerBrowseForward
HotKey, %mm_BrowseBackwardsTrigger%, mm_TriggerBrowseBackward
}
mm_KeyDown = n
return
;;;;;;;;;;;;;;;;
;; SETTERS
;;;;;;;;;;;;;;;;
;; //The backward action in the browser
mm_TriggerBrowseBackward:
if mm_EnableFocusGain = y
GainFocus()
SendInput, {Browser_Back}
return
;; //The forward action in the browser
mm_TriggerBrowseForward:
if mm_EnableFocusGain = y
GainFocus()
SendInput, {Browser_Forward}
return
;; //Scroll is triggered, update timers
mm_ScrollTriggerDown:
if mm_EnableFocusGain = y
GainFocus()
mm_HasMoved = n
mm_KeyDown = y
MouseGetPos, temp_OldX, temp_OldY
MouseGetPos, temp_OrigX, temp_OrigY
SetTimer, mm_CheckForScrollEvent, %mm_TimerDelay%
return
;; //Scroll is untriggered (key up), check if it was a simple click or if we scrolled
mm_ScrollTriggerUp:
;; //Key is not down any more
mm_KeyDown = n
;; //Turn of the scrollevent timer
SetTimer, mm_CheckForScrollEvent, Off
;; //Send a middle-click if we did not scroll
if mm_HasMoved = n
MouseClick, Middle
return
;; //Used for checking scroll position
mm_CheckForScrollEvent:
;; //If there is no key down, we don't want to do anything
if mm_KeyDown = n
{
SetTimer, mm_CheckForScrollEvent, Off
return
}
;; //Get the current position
MouseGetPos, mm_NewX, mm_NewY
;; //Calculate the difference in Y
if mm_EnableScrollY = y
mm_MoveDistanceY := (mm_NewY - temp_OldY)
else
mm_MoveDistanceY := 0
if mm_EnableScrollX = y
mm_MoveDistanceX := (mm_NewX - temp_OldX)
else
mm_MoveDistanceX := 0
;; //Have we moved or not?
if (mm_MoveDistanceY == 0 && mm_MoveDistanceX == 0)
return
;; //We have movement, so no middle click
mm_HasMoved = y
if Abs(mm_MoveDistanceY) > Abs(mm_MoveDistanceX) // mm_XScrollDivider
{
;; //Check if we moved down or up
if mm_MoveDistanceY > 0
{
;; //Moved down, move the scroll the correct position
Loop
{
if mm_MoveDistanceY <= 0
break
MouseClick, WheelDown
mm_MoveDistanceY -= mm_ScrollAcceleration * mm_VerticalScrollMultiplier
}
}
else if mm_MoveDistanceY < 0
{
;; //We moved up
Loop
{
;; //Loop until the distance has changed to below zero
if mm_MoveDistanceY >= 0
break
MouseClick, WheelUp
mm_MoveDistanceY += mm_ScrollAcceleration * mm_VerticalScrollMultiplier
}
}
}
else
{
;; //Check if we moved right or left
if mm_MoveDistanceX > 0
{
;; //Moved right, move the scroll the correct position
Loop
{
if mm_MoveDistanceX <= 0
break
MouseClick, WheelRight
mm_MoveDistanceX -= mm_ScrollAcceleration * mm_HorizontalScrollMultiplier
}
}
else if mm_MoveDistanceX < 0
{
;; //We moved left
Loop
{
;; //Loop until the distance has changed to below zero
if mm_MoveDistanceX >= 0
break
MouseClick, WheelLeft
mm_MoveDistanceX += mm_ScrollAcceleration * mm_HorizontalScrollMultiplier
}
}
}
;; //Move and reset mouse position
MouseMove, temp_OrigX, temp_OrigY
MouseGetPos, temp_OldX, temp_OldY
return
;;;;;;;;;;;;;;;;
;; HELPERS
;;;;;;;;;;;;;;;;
;; //Sets focus for a window
GainFocus()
{
;; //Get mouse window
MouseGetPos,,, MouseWin
;; //Make a dll call to ask for focus
DllCall("SwitchToThisWindow", "UInt", MouseWin, "UInt", 1)
}