1

As I understood, SendKeys class provides methods to send keys to whatever application is active. I would like to send keys to the current application only, without making it active. I mean the application whose code sends the keys. So I would like the current application to stay in background and still send keys to itself. How to do this?

Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158
  • why do you want to do this. it seems to me, this is not the right approach to whatever you're trying to accomplish. – adjan Jun 04 '17 at 09:05
  • @adjan , it's a part of a workaround for `input` tag html element not allowing to set `value` attribute even in a `WebBrowser` control. – Serge Rogatch Jun 04 '17 at 09:07
  • https://stackoverflow.com/questions/14681335/setting-value-of-an-input-tag-in-webbrowser-control <-- This does not work? – adjan Jun 04 '17 at 09:09
  • @adjan, that's for text input, not for file upload. Here's a modern solution for file upload: https://stackoverflow.com/questions/18687876/uploading-files-not-working-need-assistance/18691219#18691219 . The problem with it is that it brings the current application to foreground or sends keys to whatever application is currently in foreground. I would like to continue working on something else while the file is being uploaded. – Serge Rogatch Jun 04 '17 at 09:14
  • It is possible to send key strokes to an application in the background, **but the application only**. Once the modal dialog opens it is very hard to determine its window handle unless it is focused. Thus unless you want to get into some real dirty workarounds the best thing is to let it have focus. – Visual Vincent Jun 04 '17 at 09:20
  • @VisualVincent, it's not an option to let it be in the foreground because I lose the point of automation: I can't do something else in another application, because the automation app constantly brings itself to foreground. – Serge Rogatch Jun 04 '17 at 09:23
  • Well I'm sorry to say, but you're going to have a real hard time determining the window handle of the modal dialog then... Though one option could be to bring it into the foreground temporarily when opening the dialog, get the window handle, and then give focus to the previous application again. – Visual Vincent Jun 04 '17 at 09:33

0 Answers0