Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Windows Forms Apps (.Net 6) #42

Open
RobinBalean opened this issue Aug 30, 2023 · 1 comment
Open

Bug in Windows Forms Apps (.Net 6) #42

RobinBalean opened this issue Aug 30, 2023 · 1 comment

Comments

@RobinBalean
Copy link

To demonstrate this error, I created a new Windows Forms App with a text box and a button. After pressing the button the text in the text box is sent using InputSimulatorEx after a 5 Second delay like this:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private void btn_send_Click(object sender, EventArgs e)
    {
        Thread.Sleep(5000);
        var text = tb_text.Text;
        InputSimulator sim = new();
        sim.Keyboard.TextEntry(text);
    }
}

Start the app and open a notepad.exe Window to display the text. Press the button and make notepad the active window.

Single characters work fine, but if my text is longer , only the first few characters of the text appear. If I start typing in the notepad window the rest of the text shows up. (Sometimes if I wait long enough it appears too.)

The text appears to be stuck inside a buffer, which somehow needs to be nudged to start pushing out letters again.
Is there a way to do this? I tried calling SendKeys.Flush() after the TextEntry, but it didn't help.

@RobinBalean
Copy link
Author

Answering my own question...
It seems to work if you put a small sleep in between characters. Like this:

private void btn_send_Click(object sender, EventArgs e)
{
    Thread.Sleep(5000);
    var text = tb_text.Text;
    InputSimulator sim = new();
    foreach (var c in text)
    {
        sim.Keyboard.TextEntry(c);
        sim.Keyboard.Sleep(1);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant