CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Posts
    3

    Simulate keypress

    Hi,
    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
    Posts
    3

    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
    Location
    Sweden
    Posts
    3,654

    Re: Simulate keypress

    It might be as you say that DirectInput gets the input earlier in the chain but have you tried SendInput? http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
    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
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    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: http://forums.codeguru.com/showthread.php?t=513274. 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
  •  





Click Here to Expand Forum to Full Width

Featured