CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

View Poll Results: Is it even possible to do it? (post why)

Voters
2. You may not vote on this poll
  • Yes, C++ can do that!

    2 100.00%
  • No, C++ isnt designed that way, or its too complicated...

    0 0%
Results 1 to 12 of 12
  1. #1
    Join Date
    Apr 2004
    Posts
    11

    Question Hijacking keyboard and mouse datastream

    Hi!
    Im currently (trying) to learn C++
    I just had a pause (as i was overwhelmed) and to get me started again my brother gave me this challenge.
    Simply put, he needs a program that runs in the background, and when he then click a button (example 'b') it should for a short period (1-2 secs) take over his keyboard and mouse, clicking specific buttons and the right mouse button.
    After that, it should return control to him.
    If somebody could please send me a source code with documentation and a few pointers about how it works, then i'll do the rest.

    Email: [email protected]
    Or just reply here, i'll watch this thread for some time (a week or so, max)
    Last edited by TCR_A1; April 2nd, 2004 at 07:06 AM.

  2. #2
    Join Date
    Apr 2004
    Posts
    11

    Talking

    Please, anybody got a clue?
    If so, just a little clue and i'll be happy.
    Give me something to work with!

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    I'll give you the hint....Look for "Hooks"..."System Hooks" "Keyboard Hooks" "Mouse Hooks"

    Have phun!
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  4. #4
    Join Date
    Apr 2004
    Posts
    11
    sounds interesting, i'll look for it.
    BTW, that doenst stop y'all to contribute!
    Hints? Clues? SOLUTIONS?

  5. #5
    Join Date
    Apr 2004
    Posts
    11
    Seached on it.
    A little confused, but i think i manage...
    However, this only detects systemwide keyboard and mouse INPUT, but how to change that input through manipulation?
    So that when i run the program, everytime i hit 'b' the program will hit 'g' 'LeftClick' 'n' 'LeftClick' 'F5' son on so forth.
    How is this possible, if it is?

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    Simply hange the key within the handler.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Apr 2004
    Posts
    11
    Sounds simple, all in one sentence.
    ..
    Didnt understand
    Understand, im COMPLETELY new to C++, i only know how to do things like getting to program to calculate, accept input and doing loops and variebles so on and so on.

    So, i would REALLY like some background info, including a sample source code doing what im asking for, with comments and documentation

    Hey, my brother just said he would pay me 100 DKK (Danske Kroner) Danish valuta
    For it!
    Rocks... if i can get it to work

  8. #8
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899
    i give you just one little implementation

    Code:
    while ( true )
    {
          if ( GetAsyncKeyState(VK_ESCAPE) )
          {
              MessageBox(0, "***? The Escape button was pressed!", "*omfg*", 0);
          }
    }
    Have fun
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  9. #9
    Join Date
    Apr 2004
    Posts
    11
    errr, thanks

    What i meant was, that when i - example - press the button 'b' with the program running in the BACKGROUND the program will press 'f' 'u' 'c' 'k' 'Enter' in the program currently in front (chat joke)
    So, it detects im hitting 'b' even through the program is running in the background (something about dlls and system wide... i figure that out later) and then it injects DIRECTLY into the keyboard input steam what i ask it to.
    So that logically effects the program that is focused/in front.

    Let me be more specific.
    My big brother needs a program to use with Diablo 2 LoD, becouse EVERYTIME he joins a game he have to activate over 6 spells, 2 of them 3 times, so he asked me - thinking i was the big computer programmer (not) - to program him a program that detects him pressing 'b' and then it would fire off all his skill shortcuts encompanied by the mouse clicks needed to fire off the "spells"/skills.

    I thought "why not" "easy money" (he would gibe me 100 DKK) i just take up learning C++ again and see what i can do.
    Well, it was soon revealed to be more complicated then expected....
    So i seached, seached and then asked here.

    Oh, and btw NoHero, what liberies(SP!) should i use for that implantmentation? (include <stdio.h> blah blah...)
    Last edited by TCR_A1; April 2nd, 2004 at 12:56 PM.

  10. #10
    Join Date
    Apr 2004
    Posts
    11
    Anyone know how to do this?

  11. #11
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    Keyboard hook, eat the b key and put out the rest of them that you need. I've posted examples in the past.

  12. #12
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673
    I do not know if the hook approach may work in games, since games are using DirectInput.

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