A script for word selection that trims the trailing space?

Can I ask for some more help, now with a different script?

I want a script that will trim the trailing space of a word selected via double-clicking. I have the following simple script, which works fine when a selected word is followed by a space but has the undesired result of "trimming" the last character of a word when followed by a punctuation mark.

 

~LButton::
SystemDoubleClickTime := DllCall("GetDoubleClickTime")

If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < SystemDoubleClickTime)
{
Send +{Left}
}
Return

  

I also have this, found somewhere some time ago, but even though it looks complicated, it has the same result:

  

~LButton::
SystemDoubleClickTime := DllCall("GetDoubleClickTime")

If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < SystemDoubleClickTime)
{
; Copy everything in the Clipboard
oldClipboard := ClipboardAll

; Empty the Clipboard
clipboard =
; CTRL+ C = copy text selected
Send ^c
; Wait until the Clipboard grabs the content
ClipWait

AutoTrim, Off
word = %Clipboard%
StringLen, len1, word

AutoTrim, On
wordWithoutSpaces = %word%
StringLen, len2, wordWithoutSpaces

IfNotEqual, len1, len2
{
Sendinput +{left} ; SHIFT LEFT
}

; Give contents back to the Clipboard
Clipboard = %oldClipboard%

; Free memory of temp variable
oldClipboard =
}
Return

Parents
  • Hi Nora,

    Eventualy I had time to have a look to the 2nd script. The reason it didn't work is because there was an error in the IfNotEqual line. Furthermore, I believe a Sleep line makes the script less erratic.

    Here is the script working:

    ~LButton::
        SystemDoubleClickTime := DllCall("GetDoubleClickTime")
        If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < SystemDoubleClickTime)
        {
            ; Copy everything in the Clipboard
            oldClipboard := ClipboardAll

            ; Empty the Clipboard
            clipboard =
            ; CTRL+ C = copy text selected
            Send ^c
            ; Wait until the Clipboard grabs the content
            ClipWait,0

            AutoTrim, Off
            word = %Clipboard%
            StringLen, len1, word

            AutoTrim, On
            wordWithoutSpaces = %word%
            StringLen, len2, wordWithoutSpaces    
            
            IfNotEqual len1,%len2%
            {
                Sleep, 100
                Sendinput +{left} ; SHIFT LEFT
            }

            ; Give contents back to the Clipboard
            Clipboard = %oldClipboard%

            ; Free memory of temp variable
            oldClipboard =
        }
    Return

    PS.: I wrote that 2nd script a couple of years ago and I couldn't find it when I wanted to use it for myslef and then I was lazy to redo it. Thanks for finding it and spotting the bug, Nora!

    … Jesús Prieto …

Reply
  • Hi Nora,

    Eventualy I had time to have a look to the 2nd script. The reason it didn't work is because there was an error in the IfNotEqual line. Furthermore, I believe a Sleep line makes the script less erratic.

    Here is the script working:

    ~LButton::
        SystemDoubleClickTime := DllCall("GetDoubleClickTime")
        If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < SystemDoubleClickTime)
        {
            ; Copy everything in the Clipboard
            oldClipboard := ClipboardAll

            ; Empty the Clipboard
            clipboard =
            ; CTRL+ C = copy text selected
            Send ^c
            ; Wait until the Clipboard grabs the content
            ClipWait,0

            AutoTrim, Off
            word = %Clipboard%
            StringLen, len1, word

            AutoTrim, On
            wordWithoutSpaces = %word%
            StringLen, len2, wordWithoutSpaces    
            
            IfNotEqual len1,%len2%
            {
                Sleep, 100
                Sendinput +{left} ; SHIFT LEFT
            }

            ; Give contents back to the Clipboard
            Clipboard = %oldClipboard%

            ; Free memory of temp variable
            oldClipboard =
        }
    Return

    PS.: I wrote that 2nd script a couple of years ago and I couldn't find it when I wanted to use it for myslef and then I was lazy to redo it. Thanks for finding it and spotting the bug, Nora!

    … Jesús Prieto …

Children
No Data