Keyhooking?

This is a discussion on Keyhooking? within the Windows Programming forums, part of the Platform Specific Boards category; What im looking for is a way to detect a key press when focus is NOT on my window, i ...

  1. #1
    That Creepy Network Guy DeepBlackMagic's Avatar
    Join Date
    Feb 2003
    Posts
    265

    Keyhooking?

    What im looking for is a way to detect a key press when focus is NOT on my window, i believe this is called keyhooking. Im just looking for a few simple lines i can stick in my program for when somebody presses like X for example it would execute BOB().
    If anybody has a good tutorial on keyhooking, providing working VC++6.x code (NOT .NET) or you can just post a few lines of it to do what i want, im very interested in hearing from you. Thanks alot for the time guys, i really appreciate what you do here.
    Last edited by DeepBlackMagic; 08-04-2003 at 01:08 PM.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Why do you want to do that?

    Key logging is a very common illegal activity, and hence discussion/advice is banned on the forums here. I think you should give a legitimate reason for your application.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    I don't know about DeepBlackMagic, but I use key hooks to provide extra functionality with my keyboard. For example, I override the "shopping" & "webcam" buttons to do things they were never intended for, and also take control over the scrollywheel to the side of the keyboard as I dislike the way the driver handles it.

    That's one example of a non-illegal use, although I must say, I can't think of many others!

  4. #4
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    Key hooking can be used as a very destructive tool, but I don't seriously see it as anything evil (if you consider the many other “bad” functions out there). It can be very useful for applications developers, like for ex. checking if the user has been idle or hook some keys as shortcuts, as _Elixia_ said. But be aver, key hooking isn’t as simple as it may appear.

    Hopefully you wont use this for any illegal activity, as andrianxw pointed out.
    Last edited by Aidman; 08-04-2003 at 04:35 PM.
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  5. #5
    That Creepy Network Guy DeepBlackMagic's Avatar
    Join Date
    Feb 2003
    Posts
    265
    If you read my previous posts, you will come to realize that just about all of my questions deal with topics with few if any uses legitimate or otherwise. In this particular case it has to do with key rebinding for an application. Im interested in useing a key that is mostly unused by various environments and replacing it with a combonation of keystrokes that is useful. The idea i had in mind has been described to several people i know and they all expressed interest in its use ranging from video games to office applications. If my window has focus my program works perfectly (i sleep for 3 seconds so they may return focus to the target window manually), all i need is the knolwedge of how to catch keypresses not directed toward my application. I understand that keylogging is illegal, bla bla bla, however if i wanted to do that i would be using one of the hundred applications that already offers such functionality.

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I'll give you a start... Check out SetWindowsHookEx. If you are dedicated enough, you'll find out the rest on your own.

    BTW, if a mod decides this in inappropriate, feel free to edit this.

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Check my email I sent you a while ago. Also, RegisterHotKey may do what you require - Windows will then do the key processing for you and simply send you a message when a user presses your hotkey, regardless of which application the key was pressed in.

  8. #8
    Registered User MicroFiend's Avatar
    Join Date
    Nov 2002
    Posts
    80
    keyhooking isnt illegal, well as long as you agreed to the idea that one is being put onto your computer lol like some peer2peer applications i know of, they let u dl the program say kazaa 4 example and at the verry end of the eula it says all sorts of crap like "i agree to allow installation of third party programs such as key loggers and other such spyware" besides keyloggers are useful aswell, as long as being used to stop the bad instead of loging credit card details lol

  9. #9
    That Creepy Network Guy DeepBlackMagic's Avatar
    Join Date
    Feb 2003
    Posts
    265
    Thanks guys, i found an older tutorial from M$. My laptop now has an autosave button, as well as 3 or 4 other random function keys. Take that you useless surf-the-net key. It doesnt compiler under VC++6.0SP5 but i got it working with nmake from the cmdline. There are a few features i would like to add but they are more windows than hooking. I basically ended up with 2 C files. One DLL that has the callbacks, and one window that allows me to install/deinstall the hooks. Thanks for the help. i think u guys are a little too paranoid around things that could potentially be used for evil. I would be too if i had a bunch of script kiddies posting asking how to make a keylogger.

  10. #10
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    I've emailed you a full example.

Popular pages Recent additions subscribe to a feed

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