none
SendKeys too slow - C# winform RRS feed

  • Question

  • Hi,

    I have written some C# code for a winform application that takes in serial data, parses it and then sends a string to excel/notepad++ via the Sendkeys.Send function.

    The sendkeys output is really fast (like a cut+paste) on my PC (windows 10 version 1809), and another PC.

    Though it is much slower (can see the characters being 'typed' out one at a time, maybe 4 or 5 per second) on 2 laptops that I've tested the code on (windows 10, version 1903, and windows 7 version 6.1 build 7601).

    I've tried to change app.config to force SendInput, ran the program as admin, and even tried turning speech recognition on, tried both send and sendwait, changed build options to x86... All with no effect.

    It is definitely the sendkeys part as when i turn it off, the serial parsing updates as soon as the serial data comes in (update to a textbox).

    Any ideas on why it is going much slower on the laptops would be appreciated as I am fresh out at the moment. The below takes a few seconds to finish, whereas on my PC is is less than 1 sec.

    SendKeys.Send("im testing sendkeys. this is a test. test test test. ");
    SendKeys.Send("\t");

    Thanks!


    • Edited by Chumbles Tuesday, November 26, 2019 1:22 AM missing question
    Tuesday, November 26, 2019 1:21 AM

Answers

  • I will leave this open for someone to answer but I found a work around for anyone else that has the same problem...

    Went with using the Windows Script Host. I can't add links here but it was on stack exchange.

    First, go Project > Add Reference > COM > Windows Script Host Object Model.

    Add using IWshRuntimeLibrary to your includes, then

    WshShell shell = new WshShell();

    shell.SendKeys("text");

    Lightning fast now...

    Hope that helps.

    • Marked as answer by Chumbles Wednesday, November 27, 2019 11:20 PM
    Tuesday, November 26, 2019 4:46 AM

All replies

  • I will leave this open for someone to answer but I found a work around for anyone else that has the same problem...

    Went with using the Windows Script Host. I can't add links here but it was on stack exchange.

    First, go Project > Add Reference > COM > Windows Script Host Object Model.

    Add using IWshRuntimeLibrary to your includes, then

    WshShell shell = new WshShell();

    shell.SendKeys("text");

    Lightning fast now...

    Hope that helps.

    • Marked as answer by Chumbles Wednesday, November 27, 2019 11:20 PM
    Tuesday, November 26, 2019 4:46 AM
  • Hi Chumbles, 

    It seems that your problem has been solved. If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 26, 2019 5:37 AM
    Moderator
  • I don't know what you are doing with Excel but it is likely you should be using the Office API to do what you are doing with it.

    As for Notepad, see my Clicking a Button in Another Application. The concepts also apply to putting text into a text box. Beginners quite often think that SendKeys is an easy solution but then they have problems with it.



    Sam Hobbs
    SimpleSamples.Info

    Tuesday, November 26, 2019 5:04 PM