Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending multiple lines of text
#1
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
 
Code:
Copy      Help
string R="""
hello:

world?

Hi!
""";
e.MouseClick();

keys.send("Ctrl+A", $"!{R}"); //NO

keys.sendt(R);  //NO

clipboard.paste(R); //OK
#2
Paste works effectively, but sometimes I need to use send (simulate input text, pressing Shift+Enter for newline). Is there a better way?
#3
Is this a feature request "add option to keys.send to use Shift+Enter instead of Enter when sending text"?
#4
Code:
Copy      Help
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();
    }
}
#5
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
 
Code:
Copy      Help
    keys.send("Ctrl+A");
    clipboard.paste(R);
#6
When clipboard.paste does not work, try

Code:
Copy      Help
clipboard.text = R;
keys.send("Ctrl+A Ctrl+V");
100.ms();
#7
In next LA

Code:
Copy      Help
opt.key.TextShiftEnter = true;
keys.sendt(R);
#8
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
#9
You probably rarely use Shift+Enter for new line. Why should keys.sendt use it by default.
#10
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}");
#11
SendKeys just calls elm.Focus and keys.send.
#12
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");
#13
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.
#14
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");


Forum Jump:


Users browsing this thread: 1 Guest(s)