ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Post New Requests Here

IDEA: Long left click as Right Click

<< < (3/3)

I've fiddled with the code a bit and I've got it working for IE, Explorer and Dragon, (Comodo' version of Chrome - so it should work with Chrome).

Basically, I did what I mentioned above - if the window and control classes match an entry in the ini file on a PMB down action, the default processing is blocked.

If the PMB up action occurs within the timeout period, then a MouseClick("primary") is sent.  If a timeout occurs before a PMB up happens, then a MouseClick("secondary") is sent.

--- Code: AutoIt ---#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Icon=favicon.ico#AutoIt3Wrapper_Res_Description=Causes a Secondary Mouse Button click when Primary Mouse Button is held down for a predetermined time#AutoIt3Wrapper_Res_Fileversion= ;**** Directives created by AutoIt3Wrapper_GUI ****#cs ----------------------------------------------------------------------------        Uses MouseOnEvent UDF by MrCreatoR         Icon by Martin Berube (         LMB2R - Causes a SMB click after holding down the PMB for a secified time.         In comments: PMB = Primary Mouse Button        SMB = Secondary Mouse Button#ce ---------------------------------------------------------------------------- #include <WinAPI.au3>#include <Array.au3>#include "MouseOnEvent.au3" ; MouseOnEvent UDF HotKeySet("^+!x", "_Exit") ; Emergency Exit hotkey (Ctrl+Alt+Shift+x)OnAutoItExitRegister(_Exit) ; Call the _Exit routine when the program is terminated somehow ; Set up the tray menuOpt("TrayMenuMode", 3)Opt("TrayOnEventMode", 1)TrayCreateItem('Exit', -1, -1, 0)TrayItemSetOnEvent(-1, '_Exit')TraySetToolTip(StringLeft(@ScriptName, StringLen(@ScriptName) - 4)) ; Set the .ini filename$sIniFile = StringLeft(@ScriptFullPath, StringLen(@ScriptFullPath) - 3) & "ini"; Time PMB should be held down before interpreting as a SMB click (milliseconds)Global $iTime = IniRead($sIniFile, "Settings", "Time", "500"); Max distance mouse can move while waiting for the above (pixels)Global $iZone = IniRead($sIniFile, "Settings", "Zone", "5"); List of Window Classes to delay PMB action onGlobal $aWinClass = IniReadSection($sIniFile, "Windows") Global $aMpos, $iStart = 0, $bBlocked = False ; Hook into the PMB events_MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT, "_PrimaryDown")_MouseSetOnEvent($MOUSE_PRIMARYUP_EVENT, "_PrimaryUp") While 1 ; Thumb twiddling loop        Sleep(10)        ; If the PMB was pressed, check to see how long for        If $iStart > 0 And TimerDiff($iStart) >= $iTime Then                $aDeltaMPos = MouseGetPos()                ; Check to see if mouse has moved outside defined limit                If Abs($aDeltaMPos[1] - $aMpos[1]) <= $iZone And _                                Abs($aDeltaMPos[0] - $aMpos[0]) <= $iZone Then                        ; All OK then do a SMB click and reset the timer                        MouseClick("secondary")                        $iStart = 0                        ; Clear flag, (from cancelled PMB), so that if we cancel context menu by                        ; clicking elsewhere we don't get something weird happening from extra PMB click                        $bBlocked = False                Else                        ; Mouse moved too far so just reset the timer                        $iStart = 0                EndIf        EndIfWEnd Func _Exit()        ; Release the event hooks and Exit        _MouseSetOnEvent($MOUSE_PRIMARYDOWN_EVENT)        _MouseSetOnEvent($MOUSE_PRIMARYUP_EVENT)        ExitEndFunc   ;==>_Exit Func _PrimaryDown() ; PMB pressed        $aMpos = MouseGetPos() ; Get current mouse position        $iStart = TimerInit() ; Initialise the timer        Local $tPoint = _WinAPI_GetMousePos() ; Pointers to mouse position        Local $hWnd = _WinAPI_WindowFromPoint($tPoint) ; Get handle of control under mouse using coords        Local $ClassName = _WinAPI_GetClassName($hWnd) ; Get Control classname        Local $hParent = _WinAPI_GetAncestor($hWnd, $GA_ROOT) ; Get handle of the root window for the control        Local $sParent = _WinAPI_GetClassName($hParent) ; Get root window classname         ; Search in array for matching window classname        Local $iIndex = _ArraySearch($aWinClass, $sParent, 1, 0, 0, 1, 1, 1)        Switch $iIndex                Case 0, -1 ; No matching Window class found                        Return 0 ; Do not Block the default processing                Case Else ; Matching Window class found                        ; Search in string for matching control classname                        Local $temp = StringInStr($aWinClass[$iIndex][1], "|" & $ClassName)                        Switch $temp                                Case 0, -1 ; No matching Control class found                                        Return 0 ; Do not Block the default processing                                Case Else ; Matching Control class found                                        $bBlocked = True ; Set a flag for when the button is released                                        Return 1 ; Block the default processing                        EndSwitch        EndSwitchEndFunc   ;==>_PrimaryDown Func _PrimaryUp() ; PMB released        ; If the timer is less than the timeout reset it otherwise it accumulates        ; If it's longer than the timeout the Thumb Twiddling Loop will take care of it        If TimerDiff($iStart) < $iTime Then                $iStart = 0                If $bBlocked Then ; If PMB down was previously blocked, send PMB and clear flag                        MouseClick("primary")                        $bBlocked = False                EndIf        EndIf        Return 0 ; Do not Block the default processingEndFunc   ;==>_PrimaryUp
.ini now contains Window and Control classnames for recalcitrant windows.

--- Code: Text ---[Settings]Time=500Zone=5[Windows]Window1=CabinetWClass|EditWindow2=IEFrame|EditWindow3=Chrome_WidgetWin_1|Chrome_WidgetWin_1
For any other windows just add a line:
Window(x)=<window classname>|<control classname>       where (x) is the next number in the sequence (it actually doesn't matter what the key name is as only the value is used).

To help you get the Window & Control classname there's a small program called Classnames.exe, (source included), that will display the classname of the Window & Control class under the pointer, eg.

Exit it using the tray menu.

Modified my original post above.

EDIT: Well, after using it for a bit, it seems to stop working after a little. I have to close and re-open it for it to work again. Any ideas as to why?

Very cool!! Works great!!  :Thmbsup:

Thanks so much!

EDIT: Well, after using it for a bit, it seems to stop working after a little. I have to close and re-open it for it to work again. Any ideas as to why?-c.gingerich (March 05, 2015, 07:46 AM)
--- End quote ---

Not really, TBH the blocking of the mouse event over specific controls is probably a bit of a hack so I'm not sure what the long term effects of doing it might be.

Do you have more info regarding this, eg. mainly working in which windows before it stops, etc. ?

The previous version without the Window/Control class workaround seemed to go quite well when I was testing just using Pale Moon, Desktop, & DOpus but it's a bit hard to test every combination.


[0] Message Index

[*] Previous page

Go to full version