CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    132

    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.

  2. #2
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    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
  •  





Click Here to Expand Forum to Full Width

Featured