How to copy pre-selected text using UI action?

Post your questions and help other users.

Moderator: Martin

LED
Posts: 45
Joined: 28 Jun 2014 00:51

How to copy pre-selected text using UI action?

Post by LED » 01 May 2016 09:45

Hi Martin.

I have managed to paste a text from the clipboard into a text field which I had in focus.

I also managed to do a "selectAll" using the control UI action with a little script.

But how do I do a "select all" followed by "copy" so the text goes directly to the clipboard without the need for a long click/copy we would normally do?

I have gone through the whole forum, the user help and through the web without success, but I'm convinced I can do it in automagic I just don't know how

Thanks

LED

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: How to copy pre-selected text using UI action?

Post by MURTUMA » 01 May 2016 11:03

Check the Control UI help section again. There is a list of functions you can use and it contains a few different methods to copy text.

LED
Posts: 45
Joined: 28 Jun 2014 00:51

Re: How to copy pre-selected text using UI action?

Post by LED » 01 May 2016 13:45

Thanks but I don't know how to use "copy(pattern)"

I want the "pattern" to be the text I pre-selected using the selectAll script. But it doesn't seem to work.

Thanks

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: How to copy pre-selected text using UI action?

Post by MURTUMA » 02 May 2016 04:30

When you have the text selected, execute function copy(x,y) where x and y are the coordinates of the text field. You can get the coordinates with the helper overlay or phone's developer setting "show pointer location". Also, after selecting the text, you might need to focus on the text field again; focus(x,y).

LED
Posts: 45
Joined: 28 Jun 2014 00:51

Re: How to copy pre-selected text using UI action?

Post by LED » 02 May 2016 09:14

Thanks again.
I understand this to be a very particular way, for a very particular app and for an specific location/field on the screen.

I need a command that copies whatever selection I have, on any app, on any screen.

I managed to apply the selected all based on the existing focus, so I don't understand why I cannot simply do the same but copying instead of selecting.

Thanks for the help anyway....but I'm nearly accepting I simply cannot do it.

Maybe if I have a way to ask automagic to dinamically tell me what field/position I'm focused on, then use it to direct it to where to copy the text from....maybe.

Cheers

LED

User avatar
MURTUMA
Posts: 697
Joined: 05 Mar 2013 22:43

Re: How to copy pre-selected text using UI action?

Post by MURTUMA » 02 May 2016 11:04

LED wrote:I managed to apply the selected all based on the existing focus, so I don't understand why I cannot simply do the same but copying instead of selecting.
That is because without source(selected text) there is nothing to copy. If you have managed to focus on a text field and select all, simply reapply the focus on the same text field and use same coordinates with copy function. This works in any app that accepts input through Control UI action. You could check what app you have running and define the coordinates in a script per app basis, or something more elaborate.

LED
Posts: 45
Joined: 28 Jun 2014 00:51

Re: How to copy pre-selected text using UI action?

Post by LED » 02 May 2016 17:32

Hi.

Thanks once again and I'm sorry for being a bit annoying here.

I understand everything you said.

However there is a thing I believe you are missing: I have managed to select the focused text just by applying the "selectAll()" command, which does not require me telling where/what/x,y of what I'm selecting. It just works in the most simplistic way. I focus on something, and the text is selected.

So why, after that, and considering the text is already fully selected, can't I apply a similar command "copy()" without having to specify the location of something automatic has already select and therefore it must know where it is?

Thanks.

LED

LED
Posts: 45
Joined: 28 Jun 2014 00:51

Re: How to copy pre-selected text using UI action?

Post by LED » 02 May 2016 18:43

Just so you understand what I'm trying to achieve, it is very simple:

I'm creating a widget overlay, which is basically a button, that shows up every time the keyboard pops up. It works, Martin already helped me on that.

Now I'd like to create an action for this button (execute flow).
All this action does is to select the entire focused text field and copy it to the clipboard.

I'd be saving myself from having to long press the text, click select all and select copy (3 actions) but I'd be doing all that in a single click on my widget.

I need to be able to do that anywhere, on any app, on any text field.

Thanks.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: How to copy pre-selected text using UI action?

Post by Martin » 02 May 2016 19:50

Currently most built-in functions require to specify the target element explicitly, however it would make sense to target the focused component. I'll add it to the todo-list.

Since you are probably already using the Automagic input method, you could also use it to use CTRL C to copy the text to the clipboard. I'm not sure if this works on all Android devices but it seems to work on a Nexus with Android 6.
You can test it by executing sendKey("C", "CTRL_ON");

Regards,
Martin

LED
Posts: 45
Joined: 28 Jun 2014 00:51

Re: How to copy pre-selected text using UI action?

Post by LED » 02 May 2016 20:18

Thanks Martin.

It just did it. Perfect.

Thanks Murtuma for the exchange of advice.

It is funny I had tried
copy("ctrl+c"). But I obviously did not have a clue how to make it work.

The entire copyall flow can be seen on the attached screen shot.

Cheers guys.
Attachments
Screenshot_2016-05-02-21-15-51.png
Screenshot_2016-05-02-21-15-51.png (119.28 KiB) Viewed 18796 times

Post Reply