AutoHotkey: Double click resets the splitter

From TotalcmdWiki
Revision as of 20:44, 16 January 2007 by SanskritFritz (talk | contribs)
Jump to navigation Jump to search

Detect a double click on the splitter, and set it to 50%.

#IfWinActive ahk_class TTOTAL_CMD
~LButton::
; Detect double click code: http://www.autohotkey.com/forum/viewtopic.php?p=62779#62779
	Loop {
		LButtonDown := GetKeyState("LButton","P")
		If (!LButtonDown)
			 Break
	}

	WaitTime:=DllCall( "GetDoubleClickTime" )/1000
	KeyWait, LButton, D T%WaitTime%
	If errorlevel=0
		GoSub, OnDoubleClick

Return

OnDoubleClick:
	; Determine the splitter class name.
	; Since there are more TPanel controls (the splitter is one of them),
	; I use the dimensions of the controls to decide.
	WinGet sf_aControls, ControlList
	Loop Parse, sf_aControls, `n
	{
		StringLeft sf_sTemp, A_LoopField, 6
		if (sf_sTemp = "TPanel")
		{
			ControlGetPos Cx,Cy,Cw,Ch, %A_LoopField%
			if (Cw < 16)
			{
				SplitterClass := A_LoopField
				Break
			}
		}
	}

	; If the mouse is over the splitter, send cm_50Percent command.
	MouseGetPos, , , , ClassUnderMouse
	if (SplitterClass = ClassUnderMouse)
	{
		; Wait for the left button to be released.
		; This is necessary, beause if we send the cm_50Percent
		; message when the button is still down, the splitter jumps back to the mouse.
		KeyWait LButton
		PostMessage 1075, 909, 0,, ahk_class TTOTAL_CMD ; cm_50Percent
	}

Return


Back to AutoHotkey