Results 1 to 11 of 11

Thread: why keybd_event does not work in this case?

  1. #1

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411

    Unhappy why keybd_event does not work in this case?

    I want to send some key strokes to another application. I tried:

    Keybd_event and sendinput

    However, it seems the application does not get the key strokes, since after keybd_event or sendinput, the application does not act as it is supposed to be (i.e. if send a 'ESC', it should pop up a window). The weird thing is if I press the 'ESC' directly, the window pops up. And, if I use my program on 'Notebook', it is ok (i.e. if I send 'a', 'a' will show in notebook the same as I press 'a' directly).

    What's the possible reason? Is it possible for me to overcome this?

    BTW, the application I'm working on is a video game.

    thanks


  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Did you try SendKeys?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    Use SendKeys.

    System.Windows.Forms.SendKeys

    Use SendKeys to send keystrokes and keystroke combinations to the active application.

    Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, pass in the string "A" to the method. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, specify the parameter as "ABC".

    The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use {+}. Brackets ([ ]) have no special meaning to SendKeys, but you must enclose them in braces. To specify brace characters, use {{} and {}}.



    ---- see MSDN

    Regards

  4. #4
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    is it possible

    that the program in question that you are trying to send your simulated key presses to is not currently in focus during the routine?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  5. #5

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411

    Re: Well ...

    Originally posted by honeybee
    Did you try SendKeys?

    .
    yes, doesnot work

  6. #6

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411
    Originally posted by sw_is_great
    Use SendKeys.

    System.Windows.Forms.SendKeys

    Use SendKeys to send keystrokes and keystroke combinations to the active application.

    ---- see MSDN


    thanks, however, I am using VB6. I'll try .NET

  7. #7

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411

    Re: is it possible

    Originally posted by TokersBall_CDXX
    that the program in question that you are trying to send your simulated key presses to is not currently in focus during the routine?
    It is currently in focus.

  8. #8
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    how do you go about

    setting focus to the program in question?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  9. #9

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411

    Re: how do you go about

    Originally posted by TokersBall_CDXX
    setting focus to the program in question?
    my program is supposed to run at the background and send key strokes to the foreground program which is a game and using DirectX for graphics.

    so, the focus must be on the game, not my program.

  10. #10
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    Are you certain DirectX is letting the keybd_event calls execute and process?

    Still, DirectInput might somehow be the culprit, although that would be a bit odd.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  11. #11

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411
    Originally posted by jemidiah
    Are you certain DirectX is letting the keybd_event calls execute and process?

    Still, DirectInput might somehow be the culprit, although that would be a bit odd.
    Yes, DX should let keybd_event calls execute and process. I tested it on another game, it is ok. It is weird that it does not work on current game.

    I searched google, another guy had this problem too. He said that he overcame this problem by installing a debug version of DX8, then it is ok. Also, all the works were on WinXP. And he had no problem on Win2k at all. It is weird, isn't it?

    I guess it is because of DX or WinXP?

    BTW, where I can donwload debug version of DX8? Can not find it on Microsoft.



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