Paste Alternative Script?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Paste Alternative Script?

28 Sep 2020, 16:23

Doing my taxes and the *&%*(^* H&R Block software will not allow me to paste numbers into the software fields... major problem.

Can someone point me to info or a script to create a new macro in my primary AHK script that will take what is in the clipboard and assign it to a key that can then be typed to the keyboard without having to load a new script?

Thanks in advance,
Beverly Howard
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: Paste Alternative Script?

28 Sep 2020, 16:38

Code: Select all

F3::Send %Clipboard%
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: Paste Alternative Script?

28 Sep 2020, 16:45

Damm... sometimes forums can make me feel pretty dumb ;-)

Thanks!

Beverly Howard
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: Paste Alternative Script?

28 Sep 2020, 16:47

It's the H&R that's killing you! I found bugs this year. Moving to Turbo next time.
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: Paste Alternative Script?

28 Sep 2020, 17:32

Now I know why I needed to ask this question.

Been using AHK for many years, but have only used it as a "menu" i.e. one hotkey starts the menu then I have cascading menus to execute over 50 macros with only one or two additional keystrokes.

So to add a dedicated hotkey in addition to the menu, is all I need to do is put key key definition after the menu code? (putting it before the menu entries doesn't work)

-====================-

Doing this, I found that I had already created a "slow paste" macro to deal with some webpages that defeat pasting and normal macros in a crude attempt to restrict data entry to normal typing speeds in an attempt to verify that a human is filling in the entry. When I tried that, it didn't work on H&R.

So, I used your suggested solution of programming a dedicated function key... and that worked... thanks!

Beverly Howard
Some programs simply can't maintain focus ;-)

Beverly Howard.
Last edited by bevhoward on 29 Sep 2020, 07:33, edited 1 time in total.
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: Paste Alternative Script?

28 Sep 2020, 18:33

You are welcome. You are correct: code to be executed upon run goes at the top, while hotkeys and hotstrings go after that. The top part is sometimes called the auto-execute section. The script executes from the top, until it encounters Return, Exit, a hotkey, a hotstring, or the end of the script-- whichever comes first. It then "stops" and waits, or follows the Return or Exit. Therefore, if you have menu-type code after a hotkey, it will never execute unless called as part of a subroutine, function, etc. If you can imagine that the name of a hotstring or hotkey is actually a label, and that the script's first such label of a hotstring or hotkey functions as Return-- both of which are true-- then you will see why the hotstrings and hotkeys must come after the code to be executed.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Paste Alternative Script?

28 Sep 2020, 19:57

It might be necessary sometimes to use either the raw or text mode:

Code: Select all

F3::SendInput % "{Text}" . Clipboard
Here's a particular case of auto-execute section with a gosub, paradoxically confirming the rule (as for static initializers, they are initialized only once and before even the script begins executing):

Code: Select all

Gosub, sub


!i::MsgBox % A_ThisHotkey ; end of the auto-execute section
!j::MsgBox % A_ThisHotkey
!k::MsgBox % A_ThisHotkey
!l::MsgBox % A_ThisHotkey


sub:
MsgBox, testing from the auto-execute section (at the bottom of the script)
return

function() {
	static _ := function()
	MsgBox % A_ThisFunc
}
A_AhkUser
my scripts
User avatar
mikeyww
Posts: 27191
Joined: 09 Sep 2014, 18:38

Re: Paste Alternative Script?

28 Sep 2020, 20:09

Good point. Adding {Text} is often recommended when the string is known to have only text, rather than any "special" characters such as modifiers.

Interesting script! A function that calls itself. I was surprised at the findings, but your explanation, well, explains them.
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: Paste Alternative Script?

29 Sep 2020, 07:30

Thanks again to both.

AHK has proven to be a key weapon in the battle against clueless form programmers ;-)

Beverly Howard
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: Paste Alternative Script?

29 Sep 2020, 17:43

You have me on the road to expanding my AHK knowledge, but I am stuck on something simple.

Code: Select all

F3::Send %Clipboard%
has quickly become valuable. I didn't realize how often that commands within AHK menus were being problematic because of loss of focus.

I now have the above macro following my menus, but, I would like to add my "Slow Paste" macro and do so by assigning it to Shift-F3 and while I know how to use modifiers in AHK output, I can't find a reference to use it with a key assignment.

Code: Select all

USLOWP:
setkeydelay 50,50
send %clipboard%
return
gregster
Posts: 9085
Joined: 30 Sep 2013, 06:48

Re: Paste Alternative Script?

29 Sep 2020, 17:46

You mean +F3:: ?
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: Paste Alternative Script?

29 Sep 2020, 17:53

You mean +F3:: ?
Yep... I think... Thanks... will proceed. That also answers the other modifier keys.

Beverly Howard
gregster
Posts: 9085
Joined: 30 Sep 2013, 06:48

Re: Paste Alternative Script?

29 Sep 2020, 17:55

You can find it in the docs in the hotkeys section (modifiers).
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: Paste Alternative Script?

29 Sep 2020, 18:07

Which then brings up multiple commands in a key assignment.

I need to add

Code: Select all

setkeydelay 50,50
as part of the command, so how do I add that before

Code: Select all

Send %Clipboard%
A related question;

I also have the "slow paste" command I need in a menu call named USLOWP:

I'm guessing that a key assignment can also execute the same routine, but don't know the syntax within a key reassignment nor if I may get something recursive.

Thanks in advance,
Beverly Howard
gregster
Posts: 9085
Joined: 30 Sep 2013, 06:48

Re: Paste Alternative Script?

29 Sep 2020, 19:25

bevhoward wrote:
29 Sep 2020, 18:07
I need to add

Code: Select all

setkeydelay 50,50
as part of the command, so how do I add that
Like you did above. But note that SetKeyDelay only works if you don't use Sendinput mode - so of you have SendMode Input somewhere at the start of the script, you will have to remove that.

I also have the "slow paste" command I need in a menu call named USLOWP:

I'm guessing that a key assignment can also execute the same routine, but don't know the syntax within a key reassignment nor if I may get something recursive.
You can stack labels (that includes hotkeys) that should share the same code, like for example:

Code: Select all

+F3::
USLOWP:
; some code
return
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: Paste Alternative Script?

29 Sep 2020, 20:10

You can stack labels (that includes hotkeys) that should share the same code, like for example:
I tried that, but AHK complained that the label was duplicated in the script.

So, I moved the USLOWP: code to the +F3:: key assignment using the sample you posted

Testing shows that the FKey reassignment works AND that when the menu command is issued, it finds the label in the F3 key reassignment and executes it as well.

Is that acceptable... In other words, is doing that going to bite me somewhere down the line?

Thanks for the education,
Beverly Howard
gregster
Posts: 9085
Joined: 30 Sep 2013, 06:48

Re: Paste Alternative Script?

29 Sep 2020, 20:17

Should be ok - that's how it's intended.

But sure, you can have labels only once (execeptions would be context-sensitive hotkeys, but we don't have them here).
As I understood it, you want to execute exactly the same code via +F3 and the menu label. Then this would be the way to go (afaics, without knowing the details).
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: Paste Alternative Script?

29 Sep 2020, 20:52

The only problem that this creates for me is that over the years I have tried to keep my .AHK script well structured and grouped. (old age, memory loss, etc. ya know)

...for example, the "U" in "USLOWP" is short for "Utility" and all of the macros in that menu are labeled starting with "U" and grouped together so that they are easy to find, edit and add to.

Of course, this need might be my permission to return to code chaos ;-)

One more related question...

When I was implementing and testing earlier, I noticed that when I had line breaks in the text contained on the clipboard, pasting the content using they keyboard (<Ctrl-V>) was as expected, but, when any of the AHK paste macros typed the clipboard content, the line breaks were doubled.

The need will probably never come up based on my needs for an alternate paste option, but can this be addressed?

Thanks again,
Beverly Howard
gregster
Posts: 9085
Joined: 30 Sep 2013, 06:48

Re: Paste Alternative Script?

29 Sep 2020, 23:04

bevhoward wrote:
29 Sep 2020, 20:52
The only problem that this creates for me is that over the years I have tried to keep my .AHK script well structured and grouped. (old age, memory loss, etc. ya know)

...for example, the "U" in "USLOWP" is short for "Utility" and all of the macros in that menu are labeled starting with "U" and grouped together so that they are easy to find, edit and add to.

Of course, this need might be my permission to return to code chaos ;-)
If you want to keep your hotkeys seprate, you can do it. Just use gosub:

Code: Select all

; Hotkeys --------------
+F3::gosub USLOWP
; more hotkeys

; Menu items ---------------
USLOWP:
; ...

When I was implementing and testing earlier, I noticed that when I had line breaks in the text contained on the clipboard, pasting the content using they keyboard (<Ctrl-V>) was as expected, but, when any of the AHK paste macros typed the clipboard content, the line breaks were doubled.

The need will probably never come up based on my needs for an alternate paste option, but can this be addressed?
Linebreaks have their own science - I would recommend to open a new topic for this question, with a detailed description of the problem (including the code to reproduce it).
User avatar
bevhoward
Posts: 56
Joined: 30 May 2016, 13:03
Location: Austin, Texas, USA
Contact:

Re: Paste Alternative Script?

30 Sep 2020, 06:51

Perfect... nice to learn so quickly.

Thanks,
Beverly Howard

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CoffeeChaton and 151 guests