0

I'm trying to write an application that can reliably send key presses to another application.

The second app has a text field which opens when 9 is pressed. Text can then be typed and then the text field is closed when Enter is pressed.

If I use SendKeys to try to do this the field does not open if I send 9, but if the field is already open my tool can send text ok, but then it does not close if I send an Enter.

I'm guessing this is because a lower-level interaction with the keyboard driver or similar is being used.

Is there a reliable way I can simulate actual keyboard input to the application from another C# app? I have found a few potential solutions online but these are generally incomplete with either missing references etc. or missing code elsewhere.

I will continue to search and I will post the solution here if I find it!

CompanyDroneFromSector7G
  • 4,291
  • 13
  • 54
  • 97
  • select an answer to say if this can be closed. Keep SO clean, and let us not inflate unanswered question count – Krishna Jul 07 '15 at 20:53

1 Answers1

0

is it an option to invoke on screen keyboard provided by os. your app, calling app will loose or cant track the key events, however if you open your second application and invove osk.exe, then the purpose of robust keyboard sending keys to an app could be fullfilled. I explained this here

EDIT: ignoring on screen keyboard

You can try using RegisterHotKey to open the textpad on a specific sequence of key(s) and persist the handle in a instance variable. On the sequence of second hot key(s) you can close the textpad (you already know the handle)

there is a video explaining this

Community
  • 1
  • 1
Krishna
  • 2,451
  • 1
  • 26
  • 31
  • not that it matters so much, but what downvotes without a comment. PS. I did mean "what" (not who) :) – Krishna Jul 06 '15 at 20:04
  • I'm guessing the same person downvoted my question and your answer. Downvoting without providing a comment as to why just demonstrates their ignorance, not lack of quality in your contribution. +1 to cancel the un-commented down-vote. – CompanyDroneFromSector7G Jul 06 '15 at 20:27
  • lets ignore those things. to the question, is this an option? – Krishna Jul 06 '15 at 20:28
  • I don't want an on-screen keyboard, I just want to send a "9" key-press to open the text field, send specific text to the text field, then send an "enter" key-press to close the text field. – CompanyDroneFromSector7G Jul 06 '15 at 20:30