-
May 29th, 2011, 04:44 AM
#1
Controling other applications, by publishing events from host application.
Hi,
I'm working on a test project in which I'm planning to control " Need For Speed " game from another application..
What I actually meant is , you might have played nfs game where the car movement is controlled by "Arrow keys/ Navigation keys "...... So I'm planning to simulate this key press event melodramatically based on some algorithm, and expecting NFS to react to it.
Here is my questions.
I can simulate key press event but , how do i need to publish it , so that other applications gets a notification that a key is pressed....
Thanks in advance.
Regards,
Vijay.
-
May 29th, 2011, 04:52 AM
#2
Re: Controling other applications, by publishing events from host application.
Did you try SendInput API?
Victor Nijegorodov
-
May 29th, 2011, 04:55 AM
#3
Re: Controling other applications, by publishing events from host application.
Hi Victor,
No I didn't try it. Ok i'll check on that.
Regards,
Vijay.
-
May 31st, 2011, 04:14 AM
#4
Re: Controling other applications, by publishing events from host application.
Hi,
I'm trying to use SendInput() Win32 API in my application to simulate keyboard left arrow key press event.
From the help document I had written below code. but this is not working , can someone help regarding the same.
Also I'm not using any UNICODE characters.
int _tmain(int argc, _TCHAR* argv[])
{
INPUT output[2];
while(1)
{
// Left key down
output[0].type = INPUT_KEYBOARD;
output[0].ki.wVk = VK_LEFT;
output[0].ki.time = 0;
output[0].ki.dwExtraInfo = 0;
// Left arrow key up
output[1].type = INPUT_KEYBOARD;
output[1].ki.wVk = VK_LEFT;
output[1].ki.dwFlags = KEYEVENTF_KEYUP ;
output[1].ki.time = 0;
output[1].ki.dwExtraInfo = 0;
int retval1 = SendInput(2, output, sizeof(INPUT));
Sleep(500);
}
return 0 ;
}
-
May 31st, 2011, 04:31 AM
#5
Re: Controling other applications, by publishing events from host application.
1. Define "not working".
2. Make sure the App you want to send keys is active before calling SendInput. SetForegroundWindow is the function to call to make it active.
3. Have a look at:
http://msdn.microsoft.com/en-us/magazine/cc163867.aspx
http://www.codeguru.com/forum/showthread.php?t=377393
Victor Nijegorodov
-
May 31st, 2011, 05:13 AM
#6
Re: Controling other applications, by publishing events from host application.
Hi Victor,
Here are the answers for your queries.
1) Define "not working".
When I run this program, and bring any other application into foreground say " MS world " and place cursor in editor area, which already has some characters typed, the cursor should move to "Left" once in every half a second , and this is not observed.
2. Make sure the App you want to send keys is active before calling SendInput. SetForegroundWindow is the function to call to make it active.
Since I want some other apps (car race ) to respond to key events, I need not call "SetForegroundWindow " in my host app. The destination app which is expected to react to key events is brought to foreground , by setting the focus on the respective form.
Yes, Thanks for the links. Kindly let me know am I missing anything in this.
Regards,
Vijay
-
May 31st, 2011, 05:23 AM
#7
Re: Controling other applications, by publishing events from host application.
Originally Posted by VijayDandur
Code:
int retval1 = SendInput(2, output, sizeof(INPUT));
What is the value of retval1?
Victor Nijegorodov
-
May 31st, 2011, 05:28 AM
#8
Re: Controling other applications, by publishing events from host application.
Return value is "2" which is successful.
-
May 31st, 2011, 05:34 AM
#9
Re: Controling other applications, by publishing events from host application.
Also, could you please let me know what is "KEYEVENTF_EXTENDEDKEY" and "KEYEVENTF_SCANCODE"
-
May 31st, 2011, 05:44 AM
#10
Re: Controling other applications, by publishing events from host application.
Please, see MSDN article KEYBDINPUT Structure
Victor Nijegorodov
-
May 31st, 2011, 06:41 AM
#11
Re: Controling other applications, by publishing events from host application.
Hi Victor,
Thanks for the info.
With the below changes, the code is working for me.
INPUT output[2];
ZeroMemory(&output, sizeof(output));
Regards,
Vijay.
-
May 31st, 2011, 01:03 PM
#12
Re: Controling other applications, by publishing events from host application.
Hi Victor,
The program is working as expected with the above code changes, but I'm facing another issue.
The intent of writing this code is to send events to another program by running this.
So, if I start this host program and bring any "car race game " which expects "arrow key events" to foreground the other application (car race or some other game) will not react to this.
but the same program when executed for windows world document, I can see that the cursor moves to left once in half a minute.
So what do I need to do to resolve this.
Regards,
Vijay.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|