Double click of mouse selects text without trailing whitespace

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
csbellmd
Posts: 3
Joined: 17 Mar 2024, 09:56

Double click of mouse selects text without trailing whitespace

Post by csbellmd » 06 Apr 2024, 11:02

I find the default Windows method of text selection when double clicking the left mouse button annoying with its inclusion of the trailing whitespace (when it exists). It is crazy to me that the default behaviour is different when using the mouse versus the keyboard touchpad. Nonetheless, the following code eliminates that trailing whitespace reliably, but it prevents a Windows default mouse action that is desired. Specifically, I want the default action of Windows to still work when a double left mouse click and hold is done, i.e., double click anywhere on a word and hold the left mouse button allowing for the selection of that entire word as well as text that is subsequent selected by dragging.

Code: Select all

~LButton::
DoubleClickTime := DllCall("GetDoubleClickTime")
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < DoubleClickTime)
{
	MouseMove 3, 0, 0, R
	MouseClick Left
	MouseClickDrag Left, 0, 0, -1, 0, 0, R
}
return
Thank you,
Clint

Rohwedder
Posts: 7659
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Double click of mouse selects text without trailing whitespace

Post by Rohwedder » 07 Apr 2024, 01:56

Hallo,
Windows only includes whitespace, i.e. the last character of the selection must be checked for it. Try:

Code: Select all

~LButton Up::
If A_PriorHotKey <> A_ThisHotKey 
Or A_TimeSincePriorHotkey > DllCall("GetDoubleClickTime")
	Return
ClipSaved := ClipboardAll
SendInput,% (ClipBoard:="") "^c"
ClipWait, 0, 0
SendInput,% ErrorLevel?"":((ClipBoard~="\s$")?"+{Left}":"")
Clipboard := ClipSaved
Return

csbellmd
Posts: 3
Joined: 17 Mar 2024, 09:56

Re: Double click of mouse selects text without trailing whitespace

Post by csbellmd » 09 Apr 2024, 08:26

Rohwedder,
I hate to be dense, but I don't understand your post I'm not sure if it is addressing the problem I am trying to solve.

Restating my issue:
- I want to be able to double click on a word to highlight (select) that word and have the whitespace not be selected with the text. That way I can quickly correct the word alone without the whitespace being included (all has to do with quick editing of my electronic medical record while using Nuance Dragon). Although I know that the clipboard can be used to trim whitespaces, the code I provided causes Windows to natively not select that whitespace by moving the mouse ever so slightly after the double click. That moving of the mouse after double clicking replicates a native Windows function that takes away that trailing whitespace. (The native Windows functionality in quite a lot of text fields is to select the word and the trailing whitespace upon double click of the word, but if you double click and move the mouse very slightly, the trailing whitespace is not included in the selection of that word).
- What I need is this: I want another native functionality of Windows to be preserved that allows a double click of the mouse and a drag while holding the second click to select the word that is double clicked on as well as any text that is selected with the drag either before or after the original double click selected word. Hope that makes sense.
-The problem with my originally posted code is that it disables the ability to do the double click and hold select functionality that was just described.

Whatcha think (or anyone else)? Thanks,
Clint

Rohwedder
Posts: 7659
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Double click of mouse selects text without trailing whitespace

Post by Rohwedder » 09 Apr 2024, 09:57

I understood exactly what you wanted, tried out your script and lo and behold: it didn't work! Whitespace to the right of a selected word remained selected!
At first I suspected that it was my file explorer setting: "Single-click to open an item (point to select)" but that was not the case.
Well, what do you do in such a case? You simply script something of your own.
My version deselects right whitespace (and only these) and allows the variation of the selection while the Lbutton is still pressed.
(Here at least)

Post Reply

Return to “Ask for Help (v1)”