-
April 25th, 2011, 05:13 PM
#1
Simulate Keypress
Hi,
I am a novice at c++ so please excuse my basic questions. I have a custom game controller that I can get data from using a small c++ console program. I want to convert some of the input to mouse and some to keypresses. So far I have it working OK, using INPUT and SendInput. If I open a notepad I can see all of the keypresses written to the page. I can also move the mouse and make button presses OK too. But when I start a game, the mouse part of it works OK, ie moving the cursor and the mouse buttons work too, but the keypresses are not getting through. Any idea how I can get my keypresses to be recognised by a game? Any help will be greatly appreciated.
-
April 27th, 2011, 06:36 PM
#2
Re: Simulate Keypress
Make certain that the target window/application has focus before using SendInput. Call SetForegroundWindow() as described in this article: http://msdn.microsoft.com/en-us/magazine/cc163867.aspx
Others have pointed out the SetForgroundWindow might no longer work as intended. If you continue to have difficulties, try calling SwitchToThisWindow (followed by SetForegroundWindow just for good measure).
Mike
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
|