CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2000
    Location
    Buffalo, NY USA
    Posts
    240

    keybd_event question

    I am launching console app from within this program and trying to send a required keypress using keybd_event to the launched program, but for some reason, this is not working

    #include <windows.h>

    void main( void )
    {
    WinExec("program.exe",NULL); // for simplicty
    keybd_event(65,NULL,0,0); // key down "A"
    keybd_event(65,NULL,KEYEVENTF_KEYUP,0); // key up "A"
    }




    the program requires an "A" to run, shouldn't this code provide it? In debug, if I remove the Winexec call, the keybd_event is entering an "A" into the source editor.


  2. #2
    Join Date
    Mar 2001
    Location
    California
    Posts
    336

    Re: keybd_event question

    Well you have two problems.

    1. The program takes a minute to start up
    2. The program might not have focus

    In order to fix the first one, you could use Sleep() to wait a few seconds before sending the 'A'. For the second problem, you should use SetForegroundWindow(). In order to pass that function the HWND that it needs, you will need to use FindWindow() to get a handle on program.exe.

    Not sure if that will help you... But that's one method you can use to do this.

    Good luck!

    John Peloquin
    Peloweb.com
    john@peloweb.com

  3. #3
    Join Date
    Sep 2000
    Location
    Buffalo, NY USA
    Posts
    240

    Re: keybd_event question

    I did try the sleep thing before posting (didnt work) but not FindWindow/SetForegroundwindow.

    The problem seems to be that "program.exe" cannot
    be run in a window and forces fullscreen.

    Is it possible to get a handle on an app that is running fullscreen ?

    Is there any way around this ???




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