Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi I simulated keyboard using c#,this code work fine and send command to IE, Notepad, Crome,but it fail to send command to game (I downloaded car racing game from Microsoft store and tried to send command to speedup the car using keyboard Up key likewise keyboard left key and right key to turn car left and right respectively but failed.
I referred code from following link.
http://inputsimulator.codeplex.com/[^]

I have heard of ActiveX contol but no where I could find its detail code.
I am using window 8 and vs2012 express.

Thanks in advance
Posted
Comments
[no name] 16-Aug-13 14:47pm    
If you having trouble with someone else's code, why are you not asking them about it? What do you expect from someone here?
rameshKumar1717 16-Aug-13 14:52pm    
I think that code does not work with game so expect new solution for me most probably using DirectX, second thing I need quick solution and I guess no other community is as quick as code project with million following it.
thanks
Sergey Alexandrovich Kryukov 16-Aug-13 16:02pm    
Not enough information. And I agree with ThePhantomUpvoter.
—SA

I found solution for my problem.
I downloaded " InputManagerSendingMessages example" from link
Download
InputManager library - Track user input and simulate input (mouse and keyboard)[^]
and modified a bit as given
C#
private void WriteExampleText_Click(object sender, EventArgs e)
        {
           
            Thread.Sleep(10000); 
            Keyboard.KeyDown(Keys.Up);
            Thread.Sleep(1000);
            Keyboard.KeyDown(Keys.Left);
            Thread.Sleep(1000);
            Keyboard.KeyDown(Keys.Right);

        }
Run this code and start the game(now code will run in the background), after 10 second car will get command. 
 Above code gives perfect command to ActiveX game such as "Need For Speed Underground"
I am thankful to the author, code project and experts replying to  naïve programmer like me.
 
Share this answer
 
Comments
John Kens 27-Sep-19 22:32pm    
This problem got me stuck for the longest time. Thanks for the share.
Member 15709234 8-Mar-23 16:16pm    
Thanks
It won't work. The code you've written to send keyboard messages to other applications is probably using SendKeys. This doesn't work with anything running on DirectX, which is most games. DirectX looks at the keyboard directly, bypassing the Windows messaging functions that normal applications, and SendKeys, uses.

AFAIK, there is no way to make a DirectX compatible equivilent of SendKeys, at least not without writing a device driver.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900