I am trying to restore( or even maximize ) another application and send input to it from my project. I can do it for certain applications like
private void winact()
IntPtr hWnd; //change this to IntPtr
Process processRunning = Process.GetProcesses();
string title, name;
foreach (Process pr in processRunning)
title = pr.MainWindowTitle.ToLower();
name = pr.ProcessName.ToLower();
if (title.Contains("teamspeak".ToLower()) || name.Contains("teamspeak".ToLower()))
hWnd = pr.MainWindowHandle;
SetForegroundWindow(hWnd); //set to topmost
Apparently the problem was that my application did not run with administrator rights. In order to be able to send input to other apps efficiently, the role of administrator is required.
To do this, I've added an
app.manifest to the application, and changed
requestedExecutionLevel level from
InputSimulator worked for other applications, but certain applications, such as games, consider the input to be a simple message and do not process keystrokes as actions. They are however passed to the chat. (this is what I've noticed)
In order to solve this issue, I have written a very script in autoIT which is simply taking the parameter passed to it (only 1) and sends the parameter as a keystroke to the window, currently in foreground. The script is compiled resulting in an executable which I am calling.
I am sure that there is a better way of doing it, but this is the best I've managed to do.