Trim working randomly!

Get help with using AutoHotkey and its commands and hotkeys
Nixcalo
Posts: 26
Joined: 06 Feb 2018, 04:24

Trim working randomly!

27 May 2018, 05:22

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:
User avatar
Flipeador
Posts: 1149
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Trim working randomly!

27 May 2018, 06:31

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).
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina
(If any of my code written for v2 has stopped working, send me a private message. I appreciate that you correct my English.)
AHKStudent
Posts: 656
Joined: 05 May 2018, 12:23

Re: Trim working randomly!

27 May 2018, 06:36

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
Nixcalo
Posts: 26
Joined: 06 Feb 2018, 04:24

Re: Trim working randomly!

27 May 2018, 16:47

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?
User avatar
Flipeador
Posts: 1149
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Trim working randomly!

27 May 2018, 18:50

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
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina
(If any of my code written for v2 has stopped working, send me a private message. I appreciate that you correct my English.)
AHKStudent
Posts: 656
Joined: 05 May 2018, 12:23

Re: Trim working randomly!

27 May 2018, 19:04

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?
User avatar
Flipeador
Posts: 1149
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Trim working randomly!

27 May 2018, 19:08

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)
}
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina
(If any of my code written for v2 has stopped working, send me a private message. I appreciate that you correct my English.)
User avatar
Flipeador
Posts: 1149
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Trim working randomly!

27 May 2018, 19:11

AHKStudent wrote:can you please share what program did you use to make that animation?
ShareX + Notepad3.
Spoiler
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina
(If any of my code written for v2 has stopped working, send me a private message. I appreciate that you correct my English.)
Nixcalo
Posts: 26
Joined: 06 Feb 2018, 04:24

Re: Trim working randomly!

27 May 2018, 19:18

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!
Nixcalo
Posts: 26
Joined: 06 Feb 2018, 04:24

Re: Trim working randomly!

27 May 2018, 19:23

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 :(
User avatar
Flipeador
Posts: 1149
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Trim working randomly!

27 May 2018, 19:26

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.
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina
(If any of my code written for v2 has stopped working, send me a private message. I appreciate that you correct my English.)
Nixcalo
Posts: 26
Joined: 06 Feb 2018, 04:24

Re: Trim working randomly!

27 May 2018, 20:25

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!
User avatar
Flipeador
Posts: 1149
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Trim working randomly! || SetClipboardText

27 May 2018, 21:42

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
}
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina
(If any of my code written for v2 has stopped working, send me a private message. I appreciate that you correct my English.)
AHKStudent
Posts: 656
Joined: 05 May 2018, 12:23

Re: Trim working randomly!

28 May 2018, 02:04

Flipeador wrote:
AHKStudent wrote:can you please share what program did you use to make that animation?
ShareX + Notepad3.
Spoiler
thank you :thumbup:

Return to “Ask For Help”

Who is online

Users browsing this forum: Bad husband, Google [Bot], sikongshan and 196 guests