On 30 Jul 2005 01:11:32 -0700, "Jay" <> declaimed the
following in comp.lang.python:
> ok, i thought for 2 seconds i might have created a Keylogger in python
No, all you've done is create a /user mode/ application that
reads ITS system input stream (and not even character by character --
raw_input doesn't return until a <cr> has been entered, at which point
you get all characters up to that point).
> but i still have one major think stopping me... PYTHON. when i run the
> program i have python create a file named keylog2.log and it then logs
> all keys pressed/typed in the python IDE into that file. All i want to
> know now is how do i hide or background python so that it will log all
> the keys pressed outside of Python.
>
A keylogger, at the lowest level, injects itself between the
keyboard driver and the OS dispatcher (for windowing systems, in
particular). It has to be transparent -- your program is consuming the
characters meaning they are not available anywhere else; a key logger
has to "copy" the keys (probably raw key-codes and not characters) from
the input stream without blocking them from reaching the normal
application that want them. That's why, for example, Windows (NT) uses
the <ctrl><alt><del> to get a log-in prompt. That key combination is
handled at the very lowest level of the keyboard driver, and NEVER
passes out to where a user program can intercept it -- meaning one can
not write a "login capture" program to fake a Windows login screen.
Doing key logging is highly OS dependent. Under AmigaOS, one
would inject a key handler at high-priority into the OS input stream
chain (a linked list of priority ordered programs that want to see
input). The logger would receive, on its input port, an OS packet with
the timestamp and key codes, could log it, and then return it to the OS
to be passed to the next program in the chain (some programs consume the
stream and don't pass it on). It was also easy to inject fake events --
a program could inject, for example, disk-change events that other
programs would respond to.
On Windows... I don't know for sure... Chapter 27 of
"Programming Applications for Microsoft Windows 4th Ed." might be of use
(may also be a more up-to-date version available too). It shows some
system call of AttachThreadInput() being used to link a program's input
stream (queue in the book's terminology) to another program so both
receive the same data (I think). You're logger would have to hook into
the process start-up system so that it could link to every process that
might be reading keys.
--
> ================================================== ============ <
> | Wulfraed Dennis Lee Bieber KD6MOG <
> | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <