CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 4 of 4

Thread: Simulate keypress

  1. #1
    Join Date
    Mar 2012

    Simulate keypress

    I'm programming under WindowsXP, VS, C++.

    I would like to ask you, if there is any possibility of simulating keypress through assembler?
    I've read lots of stuff on the net, but didn't found any code. I've heard of something like INT16 interrupt, but never wrote any code in assembler. (Just some stupid /add/ calls)

    __asm {
    ...? ;want to do a keypress here, but how?

    The reason why I need to use assembler calls is that keyb_event() function is being ignored by GameGuards (or maybe it's because of DirectInput in games?).

    Please, give me some hints. Can't sleep before I'm done

  2. #2
    Join Date
    Mar 2012

    Re: Simulate keypress

    I guess calling int 16h interrupt won't work on 32 bit system/compiler.
    Is there any way around to do the 16h interrupt under VS? I'm thinking also about the MASM compiler and writing my windows hook there.
    Or maybe there is another way to simulate keypress on the lowest possible level?

  3. #3
    Join Date
    Oct 2006

    Re: Simulate keypress

    It might be as you say that DirectInput gets the input earlier in the chain but have you tried SendInput?
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    and before posting

    Refresh your memory on formatting tags here

    Get your free MS compiler here

  4. #4
    Join Date
    Jun 2010

    Re: Simulate keypress

    I agree to S_M_A that hooking actually may not even be required here and would have thought of somthing like SendInput() in the first place too.

    Also, provided you actually need hooking, that can be done pretty well in C++ without the need to use assembly language at all. If, however, for some reason you really want assembly language, here's a thread discussing recording and playback of keystrokes using jounal hooks in assembly language: The Windows programms in there are pure assembly language without any C or C++ components, but at least they should illustrate the underlying idea.

    As to INT 16h, if that is of any use under 32-bit Windows at all, it would at best be useful for keyboard drivers. But actually, I think, not even those can use it in a reasonable way since it's legacy 16-bit stuff. And, for completeness, note that in order to simulate keystrokes you wouldn't call that interrupt, instead you would override it, which actually is somewhat similar to Windows hooks.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)