Clipboard overwriting

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
IvanIvanoviich
Posts: 3
Joined: 29 Jan 2021, 03:18

Clipboard overwriting

29 Jan 2021, 03:23

Hi, I've got a problem with storing clipboard to variables. It's copying contents of excel cells, so tpid and tpname should contain two different cells content.

Code: Select all

^g::
send, ^c
tpid= %clipboard%
sleep,1000
send, {RIGHT}{RIGHT}
sleep,1000
send, ^c 
tpname= %clipboard%
return
If I want then to send tpid and tpname, the tpid sends nothing and tpname sends the content supposed to be stored in tpid.
What do I do wrong?
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Clipboard overwriting

29 Jan 2021, 03:34

Try using a sleep (crude) or clipwait after each ^c.
IvanIvanoviich
Posts: 3
Joined: 29 Jan 2021, 03:18

Re: Clipboard overwriting

29 Jan 2021, 03:41

Ok , now I've go something like this

Code: Select all

^g::
send, ^c
ClipWait, [,,1]
tpid= %clipboard%
sleep,1000
send, {RIGHT}{RIGHT}
sleep,1000
send, ^c 
ClipWait, [,,1]
tpname= %clipboard%
return


^h::
send, %tpid%
sleep, 100
send, {DOWN}
sleep, 100
send, {TAB} 
send, %tpname%
return
tpid gives correct output, however tpname gives nothing
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Clipboard overwriting

29 Jan 2021, 03:52

Clipwait only waits for the clipboard to contain anything. It doesn't detect change.

Try adding a

Code: Select all

clipboard=
before the second ^c.
IvanIvanoviich
Posts: 3
Joined: 29 Jan 2021, 03:18

Re: Clipboard overwriting

29 Jan 2021, 04:00

Now it works. Thanks!!!

Could you explain why it works like that?
Pepineros
Posts: 45
Joined: 16 Apr 2018, 17:26
Location: Ireland

Re: Clipboard overwriting

29 Jan 2021, 04:16

AHK is smart enough to not execute a command until the previous command has finished. Basically, for every command in your script, AHK waits for Windows to say "I have done what you wanted" before executing the next line.

However, when you send the key combination ^c, your system will say "I have done what you wanted" as soon as it has sent that key combination to the active window (Excel, in your case). It doesn't understand that it needs to wait for the consequence of that key combination - i.e. update the clipboard. This is why we need to explicitly tell AHK "first send control+c, then wait for the clipboard to change, then continue".

Your script continued executing before the clipboard had updated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 285 guests