"Clipboard :=" does not always empty the clipboard immediately Topic is solved
-
- Posts: 150
- Joined: 28 Sep 2016, 11:14
- Contact:
"Clipboard :=" does not always empty the clipboard immediately
EDIT: problem seems to be solved thanks to the help of many people.
The problem was not about emptying the clipboard, but about the speed of the Paste that appeared a few lines below.
In the end the solution that seemed to work best was that suggested by jeeswg here, and embodied in the SafePaste() function.
Sometimes when I empty the clipboard with Clipboard := then later paste the "new clipboard" via Send, ^v, I end up with the old clipboard. In other words, Clipboard := does not always empty the keyboard immediately.
I can mitigate that with a Sleep, 200 but that's not always reliable (and potentially wasteful).
What would be the recommended loop to empty the keyboard and check that it is in fact empty?
Thanks!
Moderator Note: Edited post title to be more descriptive of the problem. ~ sinkfaze
The problem was not about emptying the clipboard, but about the speed of the Paste that appeared a few lines below.
In the end the solution that seemed to work best was that suggested by jeeswg here, and embodied in the SafePaste() function.
Sometimes when I empty the clipboard with Clipboard := then later paste the "new clipboard" via Send, ^v, I end up with the old clipboard. In other words, Clipboard := does not always empty the keyboard immediately.
I can mitigate that with a Sleep, 200 but that's not always reliable (and potentially wasteful).
What would be the recommended loop to empty the keyboard and check that it is in fact empty?
Thanks!
Moderator Note: Edited post title to be more descriptive of the problem. ~ sinkfaze
Last edited by freespacing on 07 Apr 2019, 12:30, edited 2 times in total.
Re: "Clipboard :=" does not always empty the clipboard immediately
I always write Clipboard = ; Erase clipboard and never have problems.
Cheers!
Cheers!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
Re: "Clipboard :=" does not always empty the clipboard immediately
- Are you saying that this sometimes pastes text!?
- Perhaps you could mention what programs you're using.
- E.g. NetBeans had (has?) some problems with setting the clipboard.
- A side note re. IDLE:
- Also, I did some experiments with Python's IDLE, and noticed that sometimes it reads from a 'local clipboard' instead of the regular clipboard.
- Setting the Clipboard variable always worked, but modifying individual clipboard formats, something that worked on other programs, didn't work on IDLE. If GetClipboardOwner reported IDLE as the last owner, I had to use the Clipboard variable, otherwise, I could modify just part of the clipboard, the text format, via SetClipboardData (and half-a-dozen other Winapi functions).
- I succeeded in forcing tab indentation, instead of 4-space indentation, when tab is pressed.
Code: Select all
Clipboard := ""
SendInput, ^v
- E.g. NetBeans had (has?) some problems with setting the clipboard.
- A side note re. IDLE:
- Also, I did some experiments with Python's IDLE, and noticed that sometimes it reads from a 'local clipboard' instead of the regular clipboard.
- Setting the Clipboard variable always worked, but modifying individual clipboard formats, something that worked on other programs, didn't work on IDLE. If GetClipboardOwner reported IDLE as the last owner, I had to use the Clipboard variable, otherwise, I could modify just part of the clipboard, the text format, via SetClipboardData (and half-a-dozen other Winapi functions).
- I succeeded in forcing tab indentation, instead of 4-space indentation, when tab is pressed.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: "Clipboard :=" does not always empty the clipboard immediately
Yes
You are absolutely right
The Clipboard is quite slow animal, it makes trouble lots of times
So
You have to have Sleep always
If you want you could use a loop (or another workaround) too, for sure
I'd rather recommend sleep like this
That works 100%
I promise
You are absolutely right
The Clipboard is quite slow animal, it makes trouble lots of times
So
You have to have Sleep always
If you want you could use a loop (or another workaround) too, for sure
I'd rather recommend sleep like this
Code: Select all
Clipboard =
Sleep, 33
I promise
Re: "Clipboard :=" does not always empty the clipboard immediately
Clipboard := isn't valid, either use Clipboard := "" or Clipboard =.
Cheers.
Cheers.
-
- Posts: 150
- Joined: 28 Sep 2016, 11:14
- Contact:
Re: "Clipboard :=" does not always empty the clipboard immediately
Hi everyone,
Thank you for the helpful hints.
This problem of the Clipboard not getting to empty fast enough arises in many text editors where I am running scripts (EditPad, PyCharm, even within text boxes of web browsers). It's not all the time, just some of the time, and this unpredictability is a problem.
Following the suggestions and more threads, I tried all this:
But none of this seems to be working, as Ctrl + v still sometimes sends the old clipboard.
Would be very grateful for any suggestions.
Thank you for the helpful hints.
This problem of the Clipboard not getting to empty fast enough arises in many text editors where I am running scripts (EditPad, PyCharm, even within text boxes of web browsers). It's not all the time, just some of the time, and this unpredictability is a problem.
Following the suggestions and more threads, I tried all this:
Code: Select all
; start off empty to allow ClipWait to detect when text has arrived.
Clipboard =
; it can take time for the Clipboard to clear
/* not working
loop
{
if clipboard =
break
}
*/
; While(Clipboard != "") ; not working
While(Clipboard) ; not working
Sleep, 50
Clipboard := text
ClipWait ; wait until clipboard contains data
Send, ^v
Would be very grateful for any suggestions.
Re: "Clipboard :=" does not always empty the clipboard immediately
Try this:freespacing wrote: ↑04 Apr 2019, 17:54Hi everyone,
Thank you for the helpful hints.
This problem of the Clipboard not getting to empty fast enough arises in many text editors where I am running scripts (EditPad, PyCharm, even within text boxes of web browsers). It's not all the time, just some of the time, and this unpredictability is a problem.
Following the suggestions and more threads, I tried all this:
But none of this seems to be working, as Ctrl + v still sometimes sends the old clipboard.Code: Select all
; start off empty to allow ClipWait to detect when text has arrived. Clipboard = ; it can take time for the Clipboard to clear /* not working loop { if clipboard = break } */ ; While(Clipboard != "") ; not working While(Clipboard) ; not working Sleep, 50 Clipboard := text ClipWait ; wait until clipboard contains data Send, ^v
Would be very grateful for any suggestions.
Code: Select all
Clipboard := ""
While (Clipboard != "")
Sleep, 10
MsgBox % "Clipboard is now cleared.`n`nIf this did not work, there should be text shown below:`n`n" Clipboard
-TL
-
- Posts: 150
- Joined: 28 Sep 2016, 11:14
- Contact:
Re: "Clipboard :=" does not always empty the clipboard immediately
@TL Very interesting suggestion!
With what you said and this shorter message:
the MsgBox shows nothing, but the Ctrl + v pastes the old clipboard!
At the moment a Sleep, 500 seems to solve it but that is a bit extreme (1980s-flavor latency).
With what you said and this shorter message:
Code: Select all
Clipboard := ""
While (Clipboard != "")
Sleep, 10
MsgBox %Clipboard%
At the moment a Sleep, 500 seems to solve it but that is a bit extreme (1980s-flavor latency).
Re: "Clipboard :=" does not always empty the clipboard immediately
Because, simply, your process is wrong
you'd better write down all your process in every detail
you'd better write down all your process in every detail
Re: "Clipboard :=" does not always empty the clipboard immediately
What about when you use space, or even 'abc', is there just a general issue with programs ignoring the clipboard (or ignoring it when it's blank)?
You could set up a ^v (Ctrl+V) hotkey for some programs, and then use this:
You could also inspect the clipboard with NirSoft InsideClipboard.
Perhaps you could send a message to the program, that will update/empty what it views as the clipboard contents.
Code: Select all
Clipboard := " "
while (Clipboard != " ")
Sleep, 10
MsgBox, % Clipboard
Code: Select all
SendInput, % "{Text}" Clipboard ;requires AHK v1.1.27+
Perhaps you could send a message to the program, that will update/empty what it views as the clipboard contents.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: "Clipboard :=" does not always empty the clipboard immediately
After the Send ^v are you using ClipWait? This is needed to ensure the clipboard has been refreshed by Windows before your script continues.
Edit:- Sorry, some confusion between ^v and ^c!
Edit:- Sorry, some confusion between ^v and ^c!
Last edited by TAC109 on 04 Apr 2019, 20:53, edited 1 time in total.
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
Re: "Clipboard :=" does not always empty the clipboard immediately
- Ah yes. There can be a problem if you try to set the clipboard contents just after sending Ctrl+V. You may send the new contents instead.
- I tried the following code on Notepad, and got 'def' once out of hundreds of attempts.
- Here is an attempt to wait for the paste to complete:
Clipboard: 'PasteWait': wait for paste to complete - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=37209&p=171360#p171360
- I tried the following code on Notepad, and got 'def' once out of hundreds of attempts.
Code: Select all
q:: ;test set clipboard contents after send
Clipboard := "abc"
SendInput, ^v
Clipboard := "def"
return
Clipboard: 'PasteWait': wait for paste to complete - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=37209&p=171360#p171360
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: "Clipboard :=" does not always empty the clipboard immediately
This is incorrect - you use ClipWait to wait until your clipboard contains data. You would want to use ClipWait after you clear your clipboard and are awaiting new data to populate the clipboard.
Code: Select all
ClipWait
Waits until the clipboard contains data.
ClipWait [, SecondsToWait, WaitForAnyData]
Perhaps an experiment would be to add onto the code I gave you and put ClipWait afterwards like this:
Code: Select all
Clipboard := ""
While (Clipboard != "")
Sleep, 10
MsgBox % "Clipboard is now cleared.`n`n"
. "If this did not work, there should be text shown below:`n`n"
. Clipboard
InitialTime := A_TickCount
ClipWait, 60
if (ErrorLevel = 1)
MsgBox % "No data or text populated your clipboard within the last minute"
TimeElapsed := A_TickCount - InitialTime
MsgBox % "If is text shown below, something other than AutoHotkey is filling your clipboard without you being aware of what it is."
. "`n`nThe text show below is in your clipboard:`n`n`n"
. Clipboard
. "`n`n`nIt took " TimeElapsed " milliseconds for your clipboard to be populated with data again without your permission."
Last edited by Tigerlily on 04 Apr 2019, 21:00, edited 1 time in total.
-TL
Re: "Clipboard :=" does not always empty the clipboard immediately
A sleep of 50 after sending ^v is standard. Seems to be a windows limitation.
-
- Posts: 150
- Joined: 28 Sep 2016, 11:14
- Contact:
"Ctrl + v" not sending the content of the Clipboard variable
Howdy everyone,
Thank you all very much for your helpful messages. Exciting news to report.
I have isolated the problem:
The question becomes: Is there a way to avoid always wasting a Sleep, 500, in other words is there a way to guarantee that Ctrl + v has finished before resetting the clipboard?
Here is how I reached these conclusions.
Looking at all the suggestions, including that of using NirSoft's InsideClipboard, I made a number of tests culminating in this one, where the value of the final Sleep affects the rate of errors, with 500 seeming okay.
To make sure there is no weirdness testing the Clibpoard variable itself, instead I tested the length of a dummy variable which is concatenated with Clipboard, guaranteeing a different address in memory:
Results when failing:
Thank you all very much for your helpful messages. Exciting news to report.
I have isolated the problem:
- the Clipboard is emptying correctly, but
- Ctrl + v pastes the old clipboard when I restore Clipboard with too short a sleep below Ctrl + v
- a Sleep of 300 after the Send, ^v is not enough, 500 seems to do it
Code: Select all
Send, ^v
Sleep 500 ; prevents the clipboard from changing during the paste operation
; in which case it pastes tmp_clip which is being assigned below!
Clipboard := tmp_clip ; restore the clipboard
Here is how I reached these conclusions.
Looking at all the suggestions, including that of using NirSoft's InsideClipboard, I made a number of tests culminating in this one, where the value of the final Sleep affects the rate of errors, with 500 seeming okay.
To make sure there is no weirdness testing the Clibpoard variable itself, instead I tested the length of a dummy variable which is concatenated with Clipboard, guaranteeing a different address in memory:
Code: Select all
PasteThis(text) ; use Ctrl+v instead of Send in order to avoid triggering auto-completion in certain environments
{
tmp_clip := ClipboardAll ; preserve Clipboard
dummy := ""
While(StrLen(dummy) != 1) { ; retry
Clipboard := ""
Sleep, 33 ; it either happens fast, or not at all
dummy := "@" . Clipboard ; dummy will have a different address in memory from Clipboard
}
MsgBox %dummy% ; This works and shows @, EVEN WHEN THE PASTING FAILS!
Clipboard := text ; "ABC"
ClipWait ; wait until clipboard contains data
MsgBox %Clipboard% ; This works and shows ABC !
Send, ^v ; PASTES THE WRONG THING when the value of Sleep on the next line is too low!
Sleep, 100 ; prevents the clipboard from changing during the paste operation
; a value of 500 seems to work... but is there a better way to ensure that Ctrl+v has finished?
Clipboard := tmp_clip ; restore the clipboard
ClipWait
}
Results when failing:
- 1. MsgBox %dummy% shows the correct message ("@")
2. MsgBox %Clipboard% shows the correct content that is supposed to be pasted ("ABC")
3. The function pastes the OLD clipboard (!!!), not what was shown by MsgBox %Clipboard%
4. NirSoft shows that the clipboard is the OLD clipboard
5. Basically, what happens is that Clipboard := tmp_clip has restored the clipboard before pasting, even though that line is below the Ctrl+v
Re: "Clipboard :=" does not always empty the clipboard immediately
- So it sounds like the same problem as my 'abc' and 'def' example above.
- And the 'PasteWait' script mentioned above could be a possible solution.
- In general, look for any visible difference, before/after pasting, e.g. caret position (A_CaretX/A_CaretY), cursor icon (A_Cursor), control text.
- You could also mention what control type you're pasting into. E.g. there may be alternatives to pasting for Edit/Scintilla controls.
- And the 'PasteWait' script mentioned above could be a possible solution.
- In general, look for any visible difference, before/after pasting, e.g. caret position (A_CaretX/A_CaretY), cursor icon (A_Cursor), control text.
- You could also mention what control type you're pasting into. E.g. there may be alternatives to pasting for Edit/Scintilla controls.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
-
- Posts: 150
- Joined: 28 Sep 2016, 11:14
- Contact:
Re: "Clipboard :=" does not always empty the clipboard immediately
@jeeswg
Thank you, that sounds Spot On!
You mention a PasteWait script, but I don't see it on the thread.
Would you please do me a big favor and point me to the version you like?
Don't know why my Ctrl + F didn't work the first time!
Thank you, that sounds Spot On!
Would you please do me a big favor and point me to the version you like?
Don't know why my Ctrl + F didn't work the first time!
Re: "Clipboard :=" does not always empty the clipboard immediately
Hallo.
perhaps:
perhaps:
Code: Select all
PasteThis(text) ; use Ctrl+v instead of Send in order to avoid triggering auto-completion in certain environments
{
Static tmp_clip, tmp_clip2
While, tmp_clip <> tmp_clip2
Sleep, 10 ;restoration not yet finished
tmp_clip := ClipboardAll ; preserve Clipboard
ClipBoard := text
While, tmp_clip2 <> text
tmp_clip2 := ClipBoard ;validate clipboard
Send, ^v
SetTimer, restoration, -500
Return ;don't waste time waiting for restoration
restoration:
ClipBoard := tmp_clip ; restore the clipboard
While, tmp_clip <> tmp_clip2
tmp_clip2 := ClipBoardAll ;validate clipboard
tmp_clip:="", tmp_clip2:=""
Return
}
-
- Posts: 150
- Joined: 28 Sep 2016, 11:14
- Contact:
Re: "Clipboard :=" does not always empty the clipboard immediately
@Rohwedder
Your function is working on my machine!
I don't understand it, but it works. Big big thanks...
One question since I don't understand it.
I see '500' mentioned. Is this a timeout? What happens if we reach 500 milliseconds?
Your function is working on my machine!
I don't understand it, but it works. Big big thanks...
One question since I don't understand it.
I see '500' mentioned. Is this a timeout? What happens if we reach 500 milliseconds?
Who is online
Users browsing this forum: Araphen and 410 guests