Thread: capturing keystroke from keyboard

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    2

    capturing keystroke from keyboard

    Hello. I want to intercept key to my program even if it is non active. I'am working on linux machine(ubuntu)..what should i use to do this?

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    you mean like for a keylogger?

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by dmh2000 View Post
    you mean like for a keylogger?
    +1

    Unless you have malicious intents, there's no reason to intercept keys while your program is out of focus.
    Devoted my life to programming...

  4. #4
    Registered User
    Join Date
    Jun 2013
    Posts
    2
    Quote Originally Posted by GReaper View Post
    +1

    Unless you have malicious intents, there's no reason to intercept keys while your program is out of focus.
    hmm..i dont have malicious intents, but i simply wants to know how can i do this. I think, everything in programming is worth to mention...even keylogger..."even" everything, what is related to programming..
    Last edited by bepof; 06-11-2013 at 04:51 PM.

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by bepof View Post
    hmm..i dont have malicious intents, but i simply wants to know how can i do this. I think, everything in programming is worth to mention...even keylogger..."even" everything, what is related to programming..
    Ok, for educational purposes, let's just say that what you want to do is OS-dependant, and its difficulty varies depending on whether you want to intercept or interrupt keyboard strokes.
    I'l also give you a hint about logging keys in Windows: GetKeyState , GetAsyncKeyState & GetKeyboardState
    Devoted my life to programming...

  6. #6
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Plus, it would probably require root access for your program, or very lax permissions on the appropriate input devices, or being part of an administrative group with access to those devices. Giving any program you write such access on a system is a really bad and silly idea. Distributing such a program is even worse.

    And, to be honest, of course you don't have malicious intent. No. Of course. And there aren't a million and one other things you could do first before you leap into device intervention. No. Of course.

    Hint: If you have permission to do that on the machines you want to do it on, go look through the specification of HID devices and their device nodes in Linux. That'll tell you everything you need to know. If you want a one-click "I get all the keystrokes on this secure machine even without having to do anything", then - pretty much - forget it. There's a reason it's secured and only certain programs have permission to play with input devices. The kind of reason you're trying to create. And if you have that sort of access to the machine (e.g. a virtual machine for testing), you could just change those permissions so that it did work anyway.

    (If you haven't guessed, we aren't going to help you much without you getting off your backside and saying what you've tried, why it failed, what you plan to do next, where you're stuck, show us your code, etc.)

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by bepof View Post
    hmm..i dont have malicious intents, but i simply wants to know how can i do this. I think, everything in programming is worth to mention...even keylogger..."even" everything, what is related to programming..
    That's a wonderful dream, but in the awake world, it's not a great concept to follow.

    The problem with keyloggers, and illegal hacking in general, is HUGE, and only getting bigger/worse.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Capturing keyboard input, one character at a time
    By Paul Omans in forum C Programming
    Replies: 17
    Last Post: 05-31-2013, 03:57 PM
  2. Capturing keyboard activity
    By Trooper88 in forum C Programming
    Replies: 2
    Last Post: 02-11-2012, 05:27 PM
  3. Get keystroke?
    By Babkockdood in forum C Programming
    Replies: 13
    Last Post: 06-30-2010, 09:42 PM
  4. Keystroke
    By Rez in forum Windows Programming
    Replies: 6
    Last Post: 07-04-2003, 01:24 AM
  5. keyboard capturing
    By xlnk in forum Linux Programming
    Replies: 4
    Last Post: 01-31-2003, 01:02 PM