Why are clipboard functions so unreliable in AHK?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
adaaaam
Posts: 3
Joined: 26 Apr 2014, 03:45

Why are clipboard functions so unreliable in AHK?

24 Oct 2016, 01:02

It's driving me absolutely mad, there's no reason it should be like that, it's 2016..
Guest

Re: Why are clipboard functions so unreliable in AHK?

24 Oct 2016, 01:59

Is there a question? :roll:

Post your code.

The clipboard is reliable if you understand how it works and write your code accordingly.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Why are clipboard functions so unreliable in AHK?

24 Oct 2016, 02:30

It's not AutoHotkey that doesn't work. It's more likely you failing to understand how the ClipBoard works or your target appllication messing up.
Recommends AHK Studio
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Why are clipboard functions so unreliable in AHK?

24 Oct 2016, 17:45

Make sure you are giving your computer time to actually copy or paste.

For example...

Code: Select all

f12::
WinGetTitle, CurrentWindow
Send ^c
WinActivate, Ahk_exe Notepad.exe
Send ^v
WinActivate, %CurrentWindow%
Return
With the above code, pressing F12 will often result in something like the following sequence on my system...
1. AHK stores the title of the currently active window.
2. AHK tells Windows that Ctrl+C was pressed.
3. AHK tells Windows to activate a Notepad window.
4. Windows recognizes that Ctrl+C was pressed.
5. Windows stores text onto the clipboard.
6. AHK tells Windows that Ctrl+V was pressed.
7. Windows activates the Notepad Window.
8. AHK tells Windows to activate the original window.
9. Windows recognizes that Ctrl+v was pressed.
10. Windows activates the original window.
11. Windows pastes the clipboard contents.

Due to delays in response time in Windows, the paste is often done after the window has switched back, instead of before as one would expect.
Changing the code to something like the following is the easiest way to work around these delays...

Code: Select all

f12::
WinGetTitle, CurrentWindow
Send ^c
Sleep 250
WinActivate, Ahk_exe Notepad.exe
Send ^v
Sleep 250
WinActivate, %CurrentWindow%
Return
There are more complicated methods of course. A search of these forums will help you find them. As a hint, they generally involve the ClipWait command.
SvenBent
Posts: 266
Joined: 09 Aug 2015, 01:34

Re: Why are clipboard functions so unreliable in AHK?

25 Oct 2016, 11:11

Stupid idiots whine.
Smart people explain issues, theorize and finds solutions or workarounds.

Clipboard works flawlessly here in the scripts I've been using it for.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lpanatt, macromint, Spawnova and 272 guests