#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. delay=20 ;in milliseconds ;set up hotkeys to replace left and right buttons hotkey, lbutton, lbuttonwait hotkey, rbutton, rbuttonwait ;windows+m toggles the middle mouse button functionality #m:: hotkey, lbutton, toggle hotkey, rbutton, toggle return lbuttonwait: if leftClicks > 0 ;Timer started, but we got another left click. ;The script ate the first click, so this makes two. ;Perform a double click and reset the timer. { click, left, 2 SetTimer, WaitClick, off leftClicks = 0 rightClicks = 0 timerSet = 0 return } ; Otherwise, this is the first press of a new series. Set count to 1 and start ; the timer: leftClicks = 1 if timerSet != 1 { timerSet = 1; SetTimer, WaitClick, -%delay% ;negative delay means the timer is one-time only } return rbuttonwait: if rightClicks > 0 ;Timer started, but we got another right click. ;The script ate the first click, so this makes two. ;Perform a double click and reset the timer. { click, right, 2 SetTimer, WaitClick, off leftClicks = 0 rightClicks = 0 timerSet = 0 return } ; Otherwise, this is the first press of a new series. Set count to 1 and start ; the timer: rightClicks = 1 if timerSet != 1 { timerSet = 1; SetTimer, WaitClick, -%delay% ;negative delay means the timer is one-time only } return WaitClick: ;get left/right mouse button states getkeystate, lstate, lbutton, P getkeystate, rstate, rbutton, P ;if we have recorded a left and a right click, and both buttons are currently held down, ;send a middle click if (leftClicks > 0)&&(rightClicks > 0)&&(lstate=="D")&&(rstate=="D") { Send,{mbutton down} input,,v,,lbutton,rbutton ;wait for either left or right button to go up send,{mbutton up} ;then let up the middle button } else if leftClicks > 0 ;otherwise if just a left click was recorded { send,{lbutton down} ;send a left button down event hotkey, rbutton, off ;let the right button work normally keywait, lbutton ;wait for the left button to go back up send,{lbutton up} ;send the left button up event hotkey, rbutton, on ;enable the right button's hotkey again } else if rightClicks > 0 ;otherwise if just a right click was recorded { send,{rbutton down} ;send a right button down event hotkey, lbutton, off ;let the left button work normally keywait, rbutton ;wait for the right button to go back up send,{rbutton up} ;send the right button up event hotkey, lbutton, on ;enable the left button's hotkey again } ;reset everything leftClicks = 0 rightClicks = 0 timerSet = 0 return f11::exitapp f12::reload