setText2ById() and CR

Post your questions and help other users.

Moderator: Martin

Post Reply
P-chu
Posts: 32
Joined: 05 Nov 2016 19:12

setText2ById() and CR

Post by P-chu » 19 Nov 2016 02:26

Hello all,

I already have a script working with focusById(), sendText(), and sendKey(). However, I was curious if I could simply have used setText2ById() instead. The current obstacle is that the text must end with a carriage return. Does anyone have an idea how that may be possible? I've already tried (and failed at) putting an actual carriage return at the end of the text, and also a "/r/n" at the end of the text too.
P-chu

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

Re: setText2ById() and CR

Post by Martin » 20 Nov 2016 13:45

Hi,

You can use \n within a string literal to create a newline, \r for a carriage return:
variable = "line1\nline2";

Regards,
Martin

P-chu
Posts: 32
Joined: 05 Nov 2016 19:12

Re: setText2ById() and CR

Post by P-chu » 21 Nov 2016 06:36

Hi Martin,

I've tried that. Even tried formfeed \f. The text would appear in the appropriate field box, and even a context list of suggestions based on what was entered showed up, but the carriage return (or the execution on the text entered) does not happen. Perhaps the app is confused when data is entered directly with a setText2() or such. If I try interact manually with the app afterwards, it behaves as if no new text was entered, and the context list does the vanish as it should with any other interaction outside that list.
P-chu

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

Re: setText2ById() and CR

Post by Martin » 22 Nov 2016 13:47

Hi,

I'm confused that the carriage return does not work. Are you trying to set the text in a multi-line text field or do you want to simulate an enter key to execute an action like submit/search in the app? In the latter case you probably have to use function sendKey or press a search button or use Execute Root Command: input keyevent ENTER to simulate an enter key.

Regards,
Martin

P-chu
Posts: 32
Joined: 05 Nov 2016 19:12

Re: setText2ById() and CR

Post by P-chu » 25 Nov 2016 15:05

Hi Martin,

It is not a multi-line text field, but there is no send/submit button either. It's the URL field in the stock web browser. (I noticed I failed to state correctly in the last sentence of my last reply, "the context list does not vanish [when I try to do anything else]."

I've been trying to avoid using sendKey(), keeping an extra URL shortcut, rooting my phone, or installing another app, all so that I can put a single shortcut with a proper name on my home screen. (The other app would have simply put another shortcut with the desired name to an existing URL shortcut too.)
P-chu

Post Reply