Press a key in another program.

This is a discussion on Press a key in another program. within the Windows Programming forums, part of the Platform Specific Boards category; I got some problems here. I want, in windows to be able to simulate that someone pressed a key in ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    10

    Press a key in another program.

    I got some problems here. I want, in windows to be able to simulate that someone pressed a key in another program. I tryed this without success.

    Maybe there's other ways I don't know or I'm forgetting something...

    Code:
    HWND handle=FindWindow("Program","Program");
    
    SendMessage(handle,WM_KEYDOWN, VK_I, 0);
    SendMessage(handle,WM_KEYUP, VK_I, 0);
    Please help me....

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    You dont seem to be testing the hwnd received....is it NULL?

    Also...you must send the keystroke to the window expecting to recieve it.....for example if this is sat MSWORD, you can use FindWindow() to get the main window....but that will not be the window accepting focus...so then you need to find the child window that will accept the keystroke...this can be done with a tool that ships with MSVC called spy++.....

    Keep in mind also that FindWindow() will not give access to child windows.....you need to use it to find the main window and then use FindWindowEx() to enumerate the child windows.

    Good luck

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    10
    I dont think this is the problem. I wanna control a game with another program. There's no child windows in that game.

    When I use WM_LBUTTONDOWN it works fine but I can't use the keyboard and I do not understand.

    Is there another way I could try to simulate a keypress?

  4. #4
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Lightbulb Simple!

    Well, you have to use:

    SetForegroundWindow(handle);
    SetFocus(handle);

    I can't figure out how to send keys without the window showing the window first. If anyone knows how I would like a reply please! Anyhow, use keybd_event(); like this:

    /* Once you have set the foreground window & the focus: */

    keybd_event("I", 0, 0, 0);
    keybd_event("I", 0, KEYEVENTF_KEYUP, 0);


    I hope this is what you were wanting!
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    10
    Thx a lot. It works well.

    You made a little mistake I think but I figured it out.

    It wasnt "I", but 'I'. Am I wrong?

  6. #6
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Talking My Mistake...

    Yes, you are right:

    'I' instead of "I" is correct. I was posting a quick reply not paying attention to C++ character rules! Sorry!
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  7. #7
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235
    Is it possible to enable a button in another app if it is disabled? Then send a virtual left click to it?
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    give up Jinx. people aren't responding to your posts about this because you're obviously trying to rip off some software.

    if you had half a brain, you'd be searching for the art of cracking/reverse engineering on the web. if you have no idea what i'm talking about, then just give up, you're not good enough to do it.

    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  9. #9
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235
    Well Uraldor, guess your right...(sigh)...But no one has any info that I can find on this subject...(whine) Maybe I'm the first one to think of this and (sigh, looks you in the straight in the eyes), I guess that I'm a genius after all....(thinking, will they by it?)...

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    10
    Is there a way to do that while the window is not showing?
    My thing would be more powerful.

  11. #11
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235
    I'm sure there is. Ask the !!!Great!!! Ulrador about it.
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  12. #12
    Registered User
    Join Date
    Apr 2002
    Posts
    10
    Im talking about pressing a key while in another program without having to show the program in which you press the key.

  13. #13
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235
    I know what your talk ing about, you don't want to have to change the focus of the windows and have your target app in the background, right?
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

  14. #14
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    I'm sure there is. Ask the !!!Great!!! Ulrador about it.

    grow up.

    But no one has any info that I can find on this subject

    you obviously didn't read my post properly....

    if you had half a brain, you'd be searching for the art of cracking/reverse engineering on the web
    so, search for cracking and reverse engineering. follow your nose, think for yourself...and you'll stumble across it.

    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  15. #15
    Caffienated jinx's Avatar
    Join Date
    Oct 2001
    Posts
    235
    Uh hu. Thanks for the repeat in case I didn't catch it the first time. [\sarcasm]

    http://www.google.com/search?hl=en&q...=Google+Search
    Last edited by jinx; 04-29-2002 at 03:10 PM.
    Weeel, itss aboot tieme wee goo back too Canada, eeehy boyss.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  4. Registery with api?
    By ismael86 in forum Windows Programming
    Replies: 1
    Last Post: 05-14-2002, 10:28 AM
  5. press any key
    By taveren in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 02-26-2002, 05:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21