Posts: 1,031
Threads: 246
Joined: Jul 2022
03-08-2024, 05:07 AM
(This post was last modified: 03-08-2024, 05:48 AM by Davider.)
the following code, in many controls, can only send partial text, sometimes only the first line of text, sometimes only the first two lines of text
It seems that the Enter key is being interpreted in multiline text
string R="""
hello:
world?
Hi!
""";
e.MouseClick();
keys.send("Ctrl+A", $"!{R}"); //NO
keys.sendt(R); //NO
clipboard.paste(R); //OK
Posts: 1,031
Threads: 246
Joined: Jul 2022
Paste works effectively, but sometimes I need to use send (simulate input text, pressing Shift+Enter for newline). Is there a better way?
Posts: 12,074
Threads: 141
Joined: Dec 2002
Is this a feature request "add option to keys.send to use Shift+Enter instead of Enter when sending text"?
Posts: 12,074
Threads: 141
Joined: Dec 2002
03-08-2024, 06:40 AM
(This post was last modified: 03-09-2024, 07:33 AM by Gintaras.)
wnd.switchActiveWindow();
300.ms();
string R = """
hello:
world?
Hi!
""";
keys2.SendTextWithShiftEnter(R);
static class keys2 {
/// <summary>
/// Sends text like <see cref="keys.sendt"/>. For newlines sends <c>Shift+Enter</c> inetead of <c>Enter</c>.
/// </summary>
/// <param name="s"></param>
public static void SendTextWithShiftEnter(string s) {
var k = new keys(opt.key);
foreach (var m in s.RxFindAll(@"(.+)|\R")) {
var v = m.Value;
if (m[1].Exists) k.AddText(m.Value); else k.AddKeys("Shift+Enter");
}
k.SendNow();
}
}
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-08-2024, 07:08 AM
(This post was last modified: 03-08-2024, 07:51 AM by Davider.)
Quote:Is this a feature request "add option to keys.send to use Shift+Enter instead of Enter when sending text"?
YES
Thank for your help.
The code above works well. Can it be added to the .send parameters?
Using the method below, pasting text onto certain controls may fail with a certain probability. The control displays an image as follows:
https://i.ibb.co/WK4ck8L/aa.png
keys.send("Ctrl+A");
clipboard.paste(R);
Posts: 12,074
Threads: 141
Joined: Dec 2002
When clipboard.paste does not work, try
clipboard.text = R;
keys.send("Ctrl+A Ctrl+V");
100.ms();
Posts: 12,074
Threads: 141
Joined: Dec 2002
In next LA
opt.key.TextShiftEnter = true;
keys.sendt(R);
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-28-2024, 08:58 AM
(This post was last modified: 03-28-2024, 09:00 AM by Davider.)
Do we need two lines of code?
I even think supporting multiline text should be set as default, as it includes single-line text.
Also, the following function, by default, supports multiline text, and it doesn't seem to have any adverse effects.
Quote:var e2 = w.Elm["web:TEXT", "Message ChatGPT…"].Find(1);
e2.MouseClick(); e2.SendKeys("Ctrl+A", $"!{text}");
e2.SendKeys is more stable to use than keys.sendt
Posts: 12,074
Threads: 141
Joined: Dec 2002
You probably rarely use Shift+Enter for new line. Why should keys.sendt use it by default.
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-28-2024, 09:16 AM
(This post was last modified: 03-28-2024, 09:23 AM by Davider.)
Single-line text doesn't have line breaks, whereas multiline text defaults to line breaks. Therefore, defaulting to multiline is feasible.
e2.SendKeys is more stable to use than keys.sendt and Ctrl+V
Because sometimes the window loses focus, resulting in text sending failure.
My apologies for the misunderstanding. The "SendKeys" function below inherently supports multiline text by default(TextShiftEnter = true).
var e2 = w.Elm["web:TEXT", "Message ChatGPT…"].Find(1);
e2.MouseClick(); e2.SendKeys("Ctrl+A", $"!{text}");
Posts: 12,074
Threads: 141
Joined: Dec 2002
SendKeys just calls elm.Focus and keys.send.
Posts: 1,031
Threads: 246
Joined: Jul 2022
Can the send function add a parameter to activate a specific element? Because sometimes the control may lose focus.
keys.send(elm:e, "Ctrl+A", "Ctrl+V");
OR:
keys.send(e, "Ctrl+A", "Ctrl+V");
Posts: 12,074
Threads: 141
Joined: Dec 2002
Please give one or more examples where it is necessary to call elm.Focus inside a keys.send statement instead of calling elm.Focus in a separate statement or using elm.SendKeys.
Posts: 1,031
Threads: 246
Joined: Jul 2022
03-30-2024, 02:00 PM
(This post was last modified: 03-30-2024, 02:01 PM by Davider.)
My previous expression wasn't quite accurate
Sometimes, when using keys.send, I only need to activate the window, not the elm.
keys.send(wnd:w, "Ctrl+A", "Ctrl+V");
Certainly, sometimes I can use the following method, but if I use the .find method, the window cannot use .Activate().
w.Activate(); keys.send("Ctrl+A", "Ctrl+V");
|