Left-Click Sticky Select

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Left-Click Sticky Select

Post by *Balderstrom »

Preamble:
I recently tried an incomplete File Manager: Handy File Tool from HeatSoft. I believe they use it for marketing their other pay-for Software, though with the quality of the app, it doesn't put their other software in a very good light.

Be that as it may, there were a couple things that I found interesting, one of those was "Sticky Select" - similiar to Total Commander's NC (right-click) Mouse Mode -- Except it was enabled for regular left-click mouse mode, and amusingly there was no way to unselect (all) files!

I liked it, but I don't like TC's NC mouse mode. Since we'll likely not see Sticky-Select for left-click in TC, I wrote up some AHK KeyBindings to implement it.
===============================================

I generally recommend having only ONE persistent script for specific-key remapping, hotkeys or triggers.

This should work with other called AHK scripts, like Samuel's ButtonBar eXtended, as it passes the Clicks thru when the mouse is not within one of the two File Lists, but would interfere with any other persistent scripts that attempt to remap mouse clicks.
Disclaimer: I don't use ButtonBar eXtended, so I haven't tested compatibility.

Code: Select all

;;
;; Total Commander: Right Click Sticky Select
;; Balderstrom, v1.30 09/2009
;;
;; Enable NC Mouse Mode in Total Commander options, if using this.
;;
#SingleInstance, Force 
SetBatchLines, -1
SendMode Input


Do_Key(wait, default, key, begMod="{}", endMod="{}")
{
	if( wait )	
		wait:=" Down"
	else
		wait:=""
	sendkey =%begMod%{%key%%wait%}%endMod%
	StringReplace, sendkey, sendkey,{},,All
	;;	MsgBox, sendkey: %sendkey%
	Send, %sendkey%
	if( wait == " Down" )
	{
		KeyWait, %default%
		Send, {%key% Up}
	}
return
}

Do_Click2(wait, activeEXE, default, key, begMod="{}", endMod="{}", xtra1="", xtra2="")
{
	if( WM_NCHITTEST() <> "CLIENT" )	;; MinMaxClose, Menu, etc
	{
		Do_Key( wait, default, default )
	return
	}
	MouseGetPos, ,,,aControl
	WinGetTitle, aTitle
	if(( activeEXE == "Opera" && ( !aControl || aControl == "OperaWindowClass1" || aTitle == "Bookmarks - Opera" ))
	|| ( activeEXE == "TCMD" && !RegExMatch( aControl, "^TMyListBox(1|2)$")) )
		Do_Key( wait, default, default )
	else
	if( abs(key) == "" )
		Do_Key( wait, default, key, begMod, endMod)
	else
	if( activeEXE == "TCMD" )
	{
		if( wait ) 
			KeyWait, %default%
		PostMessage, 0x433, %key%
	}

	if( xtra1 == 0x188 )
	{
		Sleep, 100
		SendMessage, 0x188, 0, 0, %aControl% ;; 0x188 is LB_GETCURSEL (for a ListBox).
		;; 0x20C == cm_ClearAll (Unselect All)
		if( %ErrorLevel% == 0 )
			PostMessage, 0x433, %xtra2% 
	}
return
}


#ifWinActive, ahk_class TTOTAL_CMD
{
	;; 
	;; If you use, Ctrl/Shift mapped to Mouse Keys the following work:
	;; 
	;; 0x20c - Unselect All when ctrl click on [..] in FileList
	;; 0xB70 == cm_ContextMenuInternalCursor
	;; 0xB6F == cm_ContextMenuInternal
	;; 0x9C4 == cm_ContextMenu
	Ctrl & LButton:: Do_Click2(0, "TCMD", "LButton", "RButton", "{Ctrl Up}{LButton}", "", 0x188, 0x20c)
	Ctrl & RButton::  Do_Click2(1, "TCMD", "RButton", 0xB70)
	Shift & RButton:: Do_Click2(1, "TCMD", "RButton", 0xB6F)
	RButton::         Do_Click2(1, "TCMD", "RButton", 0x9C4)

	;; 
	;; If instead you want to use Keyboard CTRL|Shift, then:
	;; 
	^LButton:: Do_Click2(0, "TCMD", "LButton", "RButton", "{Ctrl Up}{LButton}", "", 0x188, 0x20c)
	^RButton:: Do_Click2(1, "TCMD", "RButton", 0xB70)
	+RButton:: Do_Click2(1, "TCMD", "RButton", 0xB6F)

return
}

WM_NCHITTEST() 
{ 
	CoordMode, Mouse, Screen 
	MouseGetPos, x, y, z 
	SendMessage, 0x84, 0, (x&0xFFFF)|(y&0xFFFF)<<16,, ahk_id %z% 
	RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" . ErrorLevel+2&0xFFFFFFFF . "}(?<AREA>\w+\b)", HT) 
Return   HTAREA 
} 
v1.30: Rewrite/Cleanup of code of Do_Click() -> Do_Click2() + Do_Key()
_____: Fixes the few remaining selection annoyances.
v1.10: First Posted version.
Last edited by Balderstrom on 2009-09-22, 18:11 UTC, edited 1 time in total.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

v1.30: Rewrite/Cleanup of code of Do_Click() -> Do_Click2() + Do_Key()
____ : Fixes the few remaining selection annoyances.
Post Reply