3

I have an application in C# which sends keys to another program. To do that I call SetForegroundWindow method before sending keys which works. Problem is when I am connected to the computer using RDC and minimize the RDC window or disconnect it then keys are not sent.

It happens because when in RDC mode, SetForegroundWindow method doesn't work in minimized or disconnected state. I have tried using SetActiveWindow, SetFocus and BringWindowToTop but no luck. Is there any way to do that?

Ali
  • 1,801
  • 6
  • 43
  • 58
  • I was faced with the same concept a few weeks back -- I had wanted to detect if my RDP window/session was minimized/closed or the connection has gone inactive. I have managed to work my way around it -- so I wanted to know what you were trying to do. Why you are setting SetForegroundWindow before sending the keys. I want to know your whole purpose because as far as I know, not all native methods work in RDC mode. – Ann B. G. May 29 '12 at 16:49
  • Maybe you should consider using some API to set your values into the application's controls (by their handles) directly. That is not quite difficult actually. – Letterman Jun 19 '12 at 21:42

1 Answers1

1

This is very common problem. When you disconnect or minimize the RDP window, GUI context is lost. But you can keep RDP non-minimized (focus can be lost safely). In other words just turn full-screen mode off and switch to another window if you want to continue work locally.

In our company testing teams use master-slave approach: master host initiates remote connections and keeps them non-minimized until each GUI automation task is done.

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78