Solved

C# SendKeys to Foreground App

Posted on 2007-03-30
3
4,460 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Check my code out(2) 1 35
fomat Json objects 6 18
Different Delete Messages 7 23
XML & .net 5 21
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

11 Experts available now in Live!

Get 1:1 Help Now