C# SendKeys.SendWait() doesn't always work

后端 未结 1 1871
[愿得一人]
[愿得一人] 2021-01-06 08:06

I am trying to make an application that sends keys to an external application, in this case aerofly FS. I have previously used the SendKeys.SendWait() method with succes, bu

相关标签:
1条回答
  • 2021-01-06 08:44

    I too have run into external applications where SendKeys didn't work for me.

    As best I can tell, some applications, like applets inside a browser, expect to receive the key down, followed by a pause, followed by a key up, which I don't think can be done with SendKeys.

    I have been using a C# wrapper to the AutoIt Library, and have found it quite easy to use.

    Here's a link to quick guide I wrote for integrating AutoIt into a C# project.

    Once you have the wrapper and references, you can send "G" with the following:

    private void pressG()
    {
       AutoItX3Declarations.AU3_Send("{g}");
    }
    

    or with a pause,

    private void pressG()
    {
       AutoItX3Declarations.AU3_Send("{g down}", 0);
       AutoItX3Declarations.AU3_Sleep( 50 );          //wait 50 milliseconds
       AutoItX3Declarations.AU3_Send("{g up}", 0);
    }
    

    AutoIt also allows you programmatically control the mouse.

    0 讨论(0)
提交回复
热议问题