Solved

C# SendKeys to Foreground App

Posted on 2007-03-30
3
4,487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Expert Comment

by:Daniel Reynolds
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 86

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

734 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