Emptying Clipboard After Reloading the script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
flashyfortune
Posts: 13
Joined: 25 Aug 2021, 18:15

Emptying Clipboard After Reloading the script

29 Feb 2024, 07:38

Greetings all!!
I hope this message finds you all in good health.

I need a little help with this clipboard clearing.

know that this code below clears the clipboard

Code: Select all

Clipboard =""
However, the issue i'm having is when trying to make it work immediately i run my reload

Code: Select all

^r::reload
What i want is for the script to automatically clear my clipboard onces i hit the ctrl+R (^r::reload) and won't mess with the other script functions.
gregster
Posts: 9116
Joined: 30 Sep 2013, 06:48

Re: Emptying Clipboard After Reloading the script

29 Feb 2024, 07:43

fyi, I moved your help request from 'Scripts and Functions (v2)' - which is only for working scripts and functions in AHK v2 - to the help subforum for AHK v1 questions, based on the posted code.
AHK v2 is now the main release (although not very compatible to v1), but there is still some v1 support, although probably no version updates anymore. Please use the adequate help subforums (v1 or v2) for future questions. Thank you!
gregster
Posts: 9116
Joined: 30 Sep 2013, 06:48

Re: Emptying Clipboard After Reloading the script

29 Feb 2024, 07:48

Clipboard ="" actually won't clear your clipboard, but put the literal string "" into it - because you used the legacy assignment operator =, and not "the walrus operator" :=. But

Code: Select all

Clipboard := ""
or Clipboard = (not recommended) would clear the clipboard.
automatically clear my clipboard onces i hit the ctrl+R (^r::reload) and won't mess with the other script functions.
So, no reload then? Then I would simply replace it:

Code: Select all

^r::Clipboard := ""
How fast Windows actually clears the clipboard, can differ and may eg depend on its contents and system load. Possibly adding SetBatchLines -1 to the top of the script will speed things up on average.

btw, in the new main release AHK v2, = is not longer supported for assignments, just :=, hopefully reducing the mix-ups.
flashyfortune
Posts: 13
Joined: 25 Aug 2021, 18:15

Re: Emptying Clipboard After Reloading the script

03 Mar 2024, 13:04

The clipboard = " " was a mistake

so what i'm looking for is to find a way to attach clipboard := " " to the ^r::reload, thus reloading and at the same time clearing the clipboard..
Do you understand me now?
gregster
Posts: 9116
Joined: 30 Sep 2013, 06:48

Re: Emptying Clipboard After Reloading the script  Topic is solved

03 Mar 2024, 13:20

Something like this?

Code: Select all

^r::
Clipboard := ""
Reload
Sleep 1000 	; If successful, the reload will close this instance during the Sleep, so the line below will never be reached. For details, see Reload docs.
MsgBox, 4,, The script could not be reloaded.
return
Or simply put Clipboard := "" into the top part of your script for auto-execution after script start, and use the original ^r::Reload line for reloading (optionally add the reload check above); I would probably try this variant first.

This means, either you reload first, or you clear the clipboard first. Whatever works better for your specific use case. More "at the same time" you most likely can't achieve since you have no absolute control about how long either action will actually take. Still this:
gregster wrote:
29 Feb 2024, 07:48
Possibly adding SetBatchLines -1 to the top of the script will speed things up on average.
(default setting in AHK v2, but not in v1)

If this doesn't help, you should elaborate on what "won't mess with the other script functions" means in this context.
I'd guess it's about gaming, but we have no idea which problems you actually encountered. Whatever the use case, some details might help the potential helpers to help you. Perhaps there are better ways to achieve your goal.
flashyfortune
Posts: 13
Joined: 25 Aug 2021, 18:15

Re: Emptying Clipboard After Reloading the script

04 Mar 2024, 15:13

Thanks So Much Sir. You're awesome. :clap: :clap: :clap: :dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: DecimalTurn and 147 guests