C # SendKeys.SendWait () not always working

I am trying to make an application that sends keys to an external application, in this case aerofly FS. I previously used the SendKeys.SendWait () method with succes, but this time it doesn't work the way I want. I want to send the G key to the application and test it with Notepad, which I get G. But in Aeroflot FS they don’t get anything at all. Pressing the G key on the keyboard really works.

This is my input code processing (from Arduino) sending keystrokes,

private void handleData(string curData) { if (curData == "1") SendKeys.SendWait("G"); else { } } 
+4
source share
1 answer

I also ran into external applications in which SendKeys did not work for me.

As far as I can tell, some applications, such as applets inside the browser, expect to get the key down, followed by a pause, followed by a key that, I think, cannot be done using SendKeys.

I use the C # wrapper in the AutoIt library and found it pretty easy to use.

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

Once you have the wrapper and links, 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 to programmatically control the mouse.

+2
source

Source: https://habr.com/ru/post/1485832/


All Articles