954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Sending Key To Another Application

Hi, im working on basic macro program. I want to select applications by window name and sending keys(f5 f1 etc.) to them basically.

The problem is, sendkeys dont work on non-active windows. I search for this problem internet.

I can get window names to combobox with;

foreach (Process FFget in Process.GetProcesses())
{
    if (FFget.MainWindowTitle.Length>1)
    {
         comboBox1.Items.Add(FFget.MainWindowTitle.ToString());                  
    }
}


Now i can select window, which is i want to sending keys. I can get any information about windows from FFget.

Im also found a basic function, which is using keybd_event.

private void Presskey(byte keyCode)
{          
  const int KEYEVENTF_EXTENDEDKEY = 0x1;
  const int KEYEVENTF_KEYUP = 0x2;
  keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
  keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}


With that i can send to keys to activate window.

Now question is how can i sending keys to non-active window.

Im found examples for delphi, but there is no for c#.

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

You should have to look at this article - http://www.codeproject.com/KB/cs/SendKeys.aspx

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Im already done similar thing to that. But i want to sending keys to non active windows, without active them.

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 
Im already done similar thing to that. But i want to sending keys to non active windows, without active them.

Read - How can I send keys to a non active window?

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You