[AHK] Drag & Drop (Lock Mouse + Improved Scroll)

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

[AHK] Drag & Drop (Lock Mouse + Improved Scroll)

Post by *Balderstrom »

A furtherance of the script from: Non-Standard Drag-and-Drop Using Mouse Behavior
To Enable "Drag Lock" (after making a file selection):
Press LButton (hold), Press RButton (down/up) ... LButton can now be physically released.

To cancel "Drag Lock"
1) Press ESC, or
2) Press LButton (hold), Press RButton (down/up)

No Change in Behaviour:
When you want to "Drop" the files, Click as usual ---
Or press & Hold RButton before Clicking to turn into a move.

Behaviour retained from the original script:
1) The Scroll Wheel affects the file panel (or tree) that the mouse is currently hovering over.
2) Pressing "Space" when "Drag Lock" is enabled, or the Mouse Cursor has changed to indicate a Drag&Drop operation, will open the Tree Panel and move the mouse cursor to that location.

Note: As with normal TC behaviour
1) Enter can be used on folders that the mouse pointer has activated to open them.
2) Files can be dropped anywhere. Tabs, BreadCrumb, Panels, Folders, etc.

Code: Select all

;;
;;	TC_DragDropLock.ahk v1.20
;;
;;		Balderstrom, Jan.2011
;;
	#SingleInstance, Force
	#Persistent
	#NoEnv
SetBatchLInes, -1
SendMode Input

return
#ifWinActive, ahk_class TTOTAL_CMD
{
	 $Space::
	{
		if( DragFileState || (GetKeyState("LButton", "P") && inStr(",50135657,155189883,162595327,337117793,", "," QueryMouseCursor() ",")))
		{
			DragFileState:=1
			SendMessage, 0x433, 3200, 0,, A	; cm_SeparateTreeOFF
			SendMessage, 0x433, 3201, 0,, A	; cm_SeparateTree1
			MouseMove, 50, 100
		}
		else
			Send, {Space}
	return
	}

	WheelUp::
	WheelDown::
	{
		if( !DragFileState )
		{
			Send, % "{" A_ThisHotKey "}"
		return
		}
		MouseGetPos,,,,aConID,3
		ControlClick,, ahk_id %aConID%,,% A_ThisHotKey
	return
	}

	$LButton::
	{
		if( DragFileState )
		{
			KeyWait, LButton
			if( !DragFileState )
				return
			Send, {LButton Up}
			TimerDFS(-1)
		return
		}
		else
			Send, {LButton Down}
	return
	}

	$LButton Up::Send, % (DragFileState ? "" : "{LButton Up}")
	
	$RButton::
	{
		if( GetKeyState("LButton", "P"))
			TimerDFS( DragFileState:=!DragFileState )
		else
		if( DragFileState )
		{
;			Send, {Enter}							; Version 1.20 - removed.
			MouseGetPos,,,,aConID,3					; Version 1.20 test.
			ControlSend,, {Enter}, ahk_id %aConID%	; Version 1.20 test.
		}
		else
			Send, {RButton Down}
	return
	}
	$RButton Up::Send, {RButton Up}


	$ESC::
	{
		if( DragFileState )
			TimerDFS( 0 )
		else
			Send, {ESC}
	return
	}

/*	
	$Enter::
	$NumPadEnter::
	{
		if( !DragFileState )
			Send, % A_ThisHotkey
		else
		{											; Version 1.20
			MouseGetPos,,,,aConID,3					; Version 1.20
			ControlSend,, {Enter}, ahk_id %aConID%	; Version 1.20
		}
	return
	}
*/	
return
}

ToolTipDFS:
	ToolTip, % "	  Drag File State: ON"
return

TimerDFS(onOFF)
{
	Global DragFileState

	if( onOFF == 1 )
		SetTimer, ToolTipDFS, 250
	else
	{
		DragFileState:=0
		SetTimer, ToolTipDFS, OFF
		ToolTip
		if( onOFF <> -1 )
		{
			Send, {ESC}
			MsgBox,,,Drag File State: OFF,1
		}
	}
return
}


QueryMouseCursor()
{
	VarSetCapacity(CurrentCursorStruct, 20, 0)
	NumPut( 20, CurrentCursorStruct, 0 )
	result := DllCall("GetCursorInfo", "str", CurrentCursorStruct)
return (NumGet(CurrentCursorStruct, 8))
}
Last edited by Balderstrom on 2011-01-13, 21:35 UTC, edited 2 times in total.
sgp
Senior Member
Senior Member
Posts: 355
Joined: 2005-01-31, 16:04 UTC

Post by *sgp »

This is a fantastic usability improvement, it should be standard in TC. Thank you! I used it on Wini7 and it worked great.

However, on WinXP SP3 pressing ENTER while hovering over a folder didn't open the folder. It isn't a fault of your script because even without it my WinXP TC doesn't open folders while dragging and pressing ENTER. Is there some hidden wincmd.ini setting to enable that behavior?
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Cool. As far as that Enter issue... I don't know, I've tried a few of the actual GUI config options and I haven't been able to stop Enter from working 'normally'. As well I've tried a few of the settings in the help file that have "Enter" in their name - to no change.

I did notice a few missing "returns" in the above code, I've added those in. What you could try is uncomment the $Enter above, on line 85. Not sure if that will make a difference or not, when I enabled it there was no change.

Now what cannot work, is Enter will not open a folder in the panel that the drag/drop started from. TC will cancel a Drag & Drop if the files are no longer selected in the starting panel. So you cannot open a folder there or change tabs in that panel.

I've also not been able to get TC to change tabs in the opposing (target) panel when LButton is down.

The only other thing that people try when odd issues arise is to close TC, back up/rename your wincmd.ini to wincmd.ini.bak, and start TC so it recreates a clean config file.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Note: You may have a TC overriding shortcut for "Enter" ...

You could also try version 1.20 above. And uncomment the /* ... */ block surrounding $Enter:: and $NumPadEnter::

As well, on the systems I've tried - while DragLock is enabled, RightClick sends an Enter, which opens folders in TreeView or Target Panel.
sgp
Senior Member
Senior Member
Posts: 355
Joined: 2005-01-31, 16:04 UTC

Post by *sgp »

Thank you for the update. I think I was pressing enter to open a folder in the same panel, and as you pointed out TC supports this move in the opposite panel only. All is well now. Ty also for clarifying that Rclick sends enter, so I can browse up by clicking [..] - good stuff.
Post Reply