Solved

C# SendKeys to Foreground App

Posted on 2007-03-30
3
4,466 Views
Last Modified: 2012-05-05
Hi,
I'm creating a program in C# that will run in the background on my pc. The program is a custom server and I will send a message to it remotely telling it to fake press a certain key. I have already made all of the code to receive the messages remotely and am just stuck where I actually have the key to send. I tried using SendKeys but this only seems to work for the active window whereas I want to be able to send keys remotely to the foreground app whatever it is or even to no window - just as if the key had been pressed on the keyboard.
Any ideas?
0
Comment
Question by:hackman_3vilGuy
3 Comments
 
LVL 17

Expert Comment

by:xDJR1875
ID: 18825494
Check out this thread on a microsoft forum.

It will give you clues on getting the window handle, etc and then sending the msg (sendkeys) to it.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=923086&SiteID=1
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18825771
"I tried using SendKeys but this only seems to work for the active window whereas I want to be able to send keys remotely to the foreground app whatever it is or even to no window - just as if the key had been pressed on the keyboard."

Eh?  "active window" and "foreground app" are the same thing arent' they?...

SendKeys just presses the buttons.  The app that currently has focus will receive them.

If you want lower keyboard control then use keybd_event() or the newer SendInput():
http://msdn2.microsoft.com/en-us/library/ms646310.aspx

Some examples...

keybd_event():
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20813844.html

SendInput():
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21650933.html
0
 
LVL 3

Author Comment

by:hackman_3vilGuy
ID: 18829513
I'm using SendInput API
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now