Page 1 of 1

Trim working randomly!

Posted: 27 May 2018, 05:22
by Nixcalo
Hi,

I want to trim Clipboard after pressing Control+C. It's quiteannoying as when I double click in a word, selection usually includes a space at the rightmost position. I want to trim the clipboard when pressing Control C.

Well, I am trying this (variations are welcome)

$^c:: ; I UNDERSTAND THIS $ SIGN IS NECESSARY TO USE THE SYSTEM CONTROL-C WITHIN THE HOTKEY. IT DOES NOT WORK WITHOUT IT.
SendInput ^c ; A SIMPLE COPY COMMAND (IT'S NOT COMPLETELY RELIABLE, I DON'T KNOW WHY, I USE VARIATIONS AS WELL)
Clipboard := Rtrim(clipboard, OmitChars := " ") ; TRIMS WHEN IT WANTS, DOESN'T TRIM A DAMN REST OF THE TIME :(
Return

and it works RANDOMLY. Sometimes it trims, sometimes it doesn't. Of course, I have previously tried all possible variations I can think of, both for SendInput ^c or SendInput {Control Down}c{Control Up} as for Clipboard=%Clipboard%, ClipBoard=Trim (clipboard), etc.

Of course, either it works RANDOMLY or it doesn't work at all (I suppose that happens when I use a wrong or incorrect syntax) but I have never got this to work 100% of the time!!

WHY??? :headwall: :headwall: :headwall:

Re: Trim working randomly!

Posted: 27 May 2018, 06:05
by just me

Re: Trim working randomly!

Posted: 27 May 2018, 06:31
by Flipeador
I want to trim Clipboard after pressing Control+C. It's quiteannoying as when I double click in a word, selection usually includes a space at the rightmost position. I want to trim the clipboard when pressing Control C.
You can avoid this easily without the need of a script. Double click on a word but do not release the left mouse button. Now move the mouse over the word in any direction once, as little as possible (to avoid selecting other words too).

Re: Trim working randomly!

Posted: 27 May 2018, 06:36
by AHKStudent
Flipeador wrote:
I want to trim Clipboard after pressing Control+C. It's quiteannoying as when I double click in a word, selection usually includes a space at the rightmost position. I want to trim the clipboard when pressing Control C.
You can avoid this easily without the need of a script. Double click on a word but do not release the left mouse button. Now move the mouse over the word in any direction once, as little as possible (to avoid selecting other words too).
That is a real good tip, been using computers for a long time never knew that

Re: Trim working randomly!

Posted: 27 May 2018, 16:47
by Nixcalo
You can avoid this easily without the need of a script. Double click on a word but do not release the left mouse button. Now move the mouse over the word in any direction once, as little as possible (to avoid selecting other words too).
I absolutely don't know what you are talking about :shock: :shock:

I have tried double clicking without releasing the left mouse button in the second click, moving a bit, and the selection does not change (nor is the space at the right removed) unless I move the pointer out of the word. And, in that case, there is no advantage at all, it's even slower than copypasting with a space ant then deleting it.

I want to trim the ClipBoard.. and my script above does not help. Any ideas?

Re: Trim working randomly!

Posted: 27 May 2018, 18:50
by Flipeador
there is no advantage at all, it's even slower than copypasting with a space ant then deleting it
I don't think so. I think if you have a decent mouse, and a minimum of skill to use it, it's just as fast. Therefore, you have an advantage.
Image

let me know if the image is not visible

Re: Trim working randomly!

Posted: 27 May 2018, 19:04
by AHKStudent
Flipeador wrote:
there is no advantage at all, it's even slower than copypasting with a space ant then deleting it
I don't think so. I think if you have a decent mouse, and a minimum of skill to use it, it's just as fast. Therefore, you have an advantage.
Image

let me know if the image is not visible
can you please share what program did you use to make that animation?

Re: Trim working randomly!

Posted: 27 May 2018, 19:08
by Flipeador
I want to trim the ClipBoard.. and my script above does not help. Any ideas?

Code: Select all

#Persistent

OnClipboardChange("OCC")
Return

OCC(Type)
{
    If (Type == 1)
        Clipboard := RTrim(Clipboard)
}

Re: Trim working randomly!

Posted: 27 May 2018, 19:11
by Flipeador
AHKStudent wrote:can you please share what program did you use to make that animation?
ShareX + Notepad3.
Spoiler

Re: Trim working randomly!

Posted: 27 May 2018, 19:18
by Nixcalo
Err.. sorry Flipeador, but since I don't understand anything of what you just did with the OnclipboardChange and all that (that's definitely about my script level, wow!), could you please tell me how to integrate that in my

Code: Select all

$^c:: 
SendInput ^c ;
Clipboard := Rtrim(clipboard, OmitChars := " ")  
Return
script.. Should this go in any place of my script? Substitute what? Change what for what?
By the way, your animation was amazing but I can tell you that does not work in my system. I keep trying it and no space is trimmed, perhaps my mouse sucks or something, but it's not working so I need the script...

Amazing how some of you guys know so much!

Re: Trim working randomly!

Posted: 27 May 2018, 19:23
by Nixcalo
Hey Flipeador!

I just put your code in the script, no hotkey, no nothing, and it works! It itches me a bit to find out I have absolutely no idea why or what the heck this is doing, but it is friggin' amazing. Dude, thank you!!! I would LOVE to know why my approach worked randomly though... I sincerely don't understand AutoHotkey sometimes :(

Re: Trim working randomly!

Posted: 27 May 2018, 19:26
by Flipeador
Nixcalo wrote:Err.. sorry Flipeador, but since I don't understand anything of what you just did with the OnclipboardChange and all that (that's definitely about my script level, wow!), could you please tell me how to integrate that in my
With OnclipboardChange is the best way to do it, since you do not have to use SendInput and declare a hotkey. Although... if text is established in another way, it also takes away the space...

Code: Select all

~^c:: 
SetTimer Label, -250
Return

Label:
Clipboard := RTrim(Clipboard)
Return

Code: Select all

$^c:: 
SendInput {lctrl down}c{lctrl up}
Sleep 250
Clipboard := Rtrim(Clipboard, A_Space)  
Return

Edit*
Nixcalo wrote:I sincerely don't understand AutoHotkey sometimes
The problem in your script is that when you do SendInput ^c you have to wait until the text is copied to the clipboard (it is not instant), SendInput returns but the text has not yet been copied. And... you do not need OmitChars in the second parameter of RTrim function. As for the rest, just read the documentation, it's very complete and clear.

Re: Trim working randomly!

Posted: 27 May 2018, 20:25
by Nixcalo
One tiny observation, Flipeador. While I see that your script seems to work great while in text environments, your script messes up Copy /Ppaste of files in Windows... or at least I am no longer able to copy and paste a file from the Windows Explorer...

Just so you know! I guess it would be a good idea then to limit your part of the script only when a certain Window (or program) is active. I will check that out!

Re: Trim working randomly! || SetClipboardText

Posted: 27 May 2018, 21:42
by Flipeador

Code: Select all

~^c:: SetTimer Label, -250

Label:
SetClipboardText( RTrim(Clipboard) )
Return

SetClipboardText(Text)
{
    DllCall("User32.dll\OpenClipboard", "Ptr", A_ScriptHwnd)
    pMem := DllCall("Kernel32.dll\GlobalAlloc", "UInt", 0x42, "UPtr", StrPut(Text, "UTF-16") * 2, "UPtr")
    pLock := DllCall("Kernel32.dll\GlobalLock", "UPtr", pMem, "UPtr")
    StrPut(Text, pLock, "UTF-16")
    DllCall("Kernel32.dll\GlobalUnlock", "UPtr", pMem, "UPtr")
    Ret := DllCall("User32.dll\SetClipboardData", "UInt", 13, "UPtr", pMem, "UPtr")    ; CF_UNICODETEXT = 13
    DllCall("User32.dll\CloseClipboard")
    If (!Ret)
        DllCall("Kernel32.dll\GlobalFree", "UPtr", pMem, "UPtr")
    Return Ret
}

Re: Trim working randomly!

Posted: 28 May 2018, 02:04
by AHKStudent
Flipeador wrote:
AHKStudent wrote:can you please share what program did you use to make that animation?
ShareX + Notepad3.
Spoiler
thank you :thumbup: