Using hotstrings as text macros doesn't work in browser.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rywi
Posts: 2
Joined: 15 Jul 2016, 01:12

Using hotstrings as text macros doesn't work in browser.

15 Jul 2016, 03:12

Hello,

I've been trying to setup short text snippets that would expand to a block of text. I have used a simple hotstring syntax, however it was not a very fast method, so I tried to implement this method found here: http://stackoverflow.com/questions/2739 ... ext-faster

Code example:

Code: Select all

::\hi::
ClipSaved := ClipboardAll       ; save clipboard
clipboard = 
(
Hello, 

How are you today?
)
ClipWait
Send, ^v
clipboard := ClipSaved       ; restore original clipboard
return
::\bye::
ClipSaved := ClipboardAll       ; save clipboard
clipboard = 
(
Bye, see you next time.
)
ClipWait
Send, ^v
clipboard := ClipSaved       ; restore original clipboard
return
However while this works on my notepad, it fails to work in most of the text fields in the browser. It seems the message is just not successfully put in the clipboard and I get my original clipboard instead.

Have you got any ideas how to fix it? Alternative ways to achieve text macros would be appreciated too. :)
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Using hotstrings as text macros doesn't work in browser.

15 Jul 2016, 04:47

Hello rywi.

I've been able to reproduce your problem and a Sleep, 100 after each ClipWait seems to fix the problem.

But you can also do this:

Code: Select all

::\hi::
(
Hello, 
 
How are you today?
)
::\bye::
(
Bye, see you next time.
)
Regards,
Antonio B.
rywi
Posts: 2
Joined: 15 Jul 2016, 01:12

Re: Using hotstrings as text macros doesn't work in browser.

15 Jul 2016, 05:21

Thank you, adding Sleep option has solved my problem. As for your alternative suggested method, I have chosen not to use it since it becomes quite slow once the text blocks are bigger.
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Using hotstrings as text macros doesn't work in browser.

15 Jul 2016, 06:38

Hello again.

You're right. I hadn't followed the Stack Overflow link :oops:

In my computer I can go as low as ClipWait + Sleep, 50 and it still works :)

I find intriguing why ClipWait doesn't seem to work as expected :think:

In fact ClipWait isn't necessary with Sleep, 100:

Code: Select all

::\hi::
FastText =
(
Hello,

How are you today?
)
Gosub, SendFast
Return

::\bye::
FastText =
(
Bye, see you next time.
)
Gosub, SendFast
Return

SendFast: ; WARNING: FastText must be defined before jumping here!
	ClipSaved := ClipboardAll ; saves current clipboard content
	Clipboard := FastText ; prepares text to be pasted
	Sleep, 100 ; ClipWait doesn't work, see https://autohotkey.com/boards/viewtopic.php?f=5&t=20311
	Send, ^v ; pastes text (fastest way to "write")
	Clipboard := ClipSaved ; restores clipboard to its original content
Return
Regards,
Antonio B.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Using hotstrings as text macros doesn't work in browser.

15 Jul 2016, 07:32

clipboard needs to be empty for clipwait to work

also waiting is not needed for assigning to the clipboard via script

but a sleep is needed after pasting as the script does not know when the program is done pasting

Code: Select all

::\hi::
ClipSaved := ClipboardAll       ; save clipboard
clipboard := "" ; clipboard needs to be empty for clipwait to work
clipboard = 
(
Hello, 
 
How are you today?
)
Send, ^v
sleep 200
clipboard := ClipSaved       ; restore original clipboard
return

::\bye::
ClipSaved := ClipboardAll       ; save clipboard
clipboard := "" ; clipboard needs to be empty for clipwait to work
clipboard = 
(
Bye, see you next time.
)
ClipWait ; not needed
Send, ^v
sleep 200
clipboard := ClipSaved       ; restore original clipboard
return
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
atnbueno
Posts: 89
Joined: 12 Oct 2013, 04:45
Contact:

Re: Using hotstrings as text macros doesn't work in browser.

15 Jul 2016, 16:02

Blackholyman, I'm sorry but I'm not sure understand your reasoning for the Sleep ("...the script does not know when the program is done pasting") :eh:

When I tried to use ClipWait, I cleared the clipboard. But this does not work :(

Code: Select all

SendFast: ; WARNING: FastText must be defined before jumping here!
	ClipSaved := ClipboardAll ; saves current clipboard content
	Clipboard := ""
	Clipboard := FastText ; prepares text to be pasted
	ClipWait
	Send, ^v ; pastes text (fastest way to "write")
	Clipboard := ClipSaved ; restores clipboard to its original content
Return
When I adapt your code, it works :thumbup:

Code: Select all

SendFast: ; WARNING: FastText must be defined before jumping here!
	ClipSaved := ClipboardAll ; saves current clipboard content
	Clipboard := ""
	Clipboard := FastText ; prepares text to be pasted
	ClipWait
	Send, ^v ; pastes text (fastest way to "write")
	Sleep, 200
	Clipboard := ClipSaved ; restores clipboard to its original content
Return
But so does this :o

Code: Select all

SendFast: ; WARNING: FastText must be defined before jumping here!
	ClipSaved := ClipboardAll ; saves current clipboard content
	; Clipboard := ""
	Clipboard := FastText ; prepares text to be pasted
	; ClipWait
	Send, ^v ; pastes text (fastest way to "write")
	Sleep, 200
	Clipboard := ClipSaved ; restores clipboard to its original content
Return
And it actually works with just a Sleep, 100, so we're almost back to my code. It seems that the Sleep command is needed, but it turns out it works both before the pasting, and between the pasting and the restoring of the clipboard :wtf:

With "...the script does not know when the program is done pasting", did you mean that without the Sleep the clipboard was restored before the pasting finished? If so, why does my code (from the previous message) also works?


Regards,
Antonio B.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Using hotstrings as text macros doesn't work in browser.

15 Jul 2016, 16:49

Clipwait is only usfull when copying

The sleep is there to let the window that gets the ^v act on that command and paste whatever is in the clipboard

If you restore the clipboard right after sending ^v the script MAY restore the clipboard to the other content before the window does the paste

Why the sleep before the send may work is unknow to me maybe it lets ahk release its hold on the clipboard before the program grabs it for the paste letting the program do the paste before ahk grabs it again to restore it to the old value
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], oktavimark and 303 guests