LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 07-05-2004, 07:39 PM   #1
chakkerz
Member
 
Registered: Dec 2002
Location: Brisbane, Australia
Distribution: Slackware Current, RedHat (RHEL, FC, CentOS), openSuSE, Mac OS X
Posts: 617
Thanked: 0
java keylogging


[Log in to get rid of this advertisement]
Hi

I'm writting a small program for my university research, and need to capture user keystrokes (already taking screen shots and tracking mouse location). I'm working in Java 1.5 Beta but any pointers would be appreachiated

OK, i need to capture user keystrokes, I was figuring something like System.in could be used but i don't know how to make it capture keystrokes outside of my program ... ie, which input stream to use. Also, i need to do this without interference to the user, so the keystrokes need to be passed forward (or not intercepted) to the program the user is passing them to.

While we are at it, i also need to capture mouse clicks (left/right/double) when they occur.

Any ideas or pointers would be appreachiated

Additional (edit)
i had been thinking that it's a simple matter of changing System.in to something more global, but that doesn't seem to be it.

I turned up something interesting though, Sockets.

Is it possible to connect a socket to the Xserver to monitor keystrokes.
Socket echoSocket = new Socket(InetAddress address, int port);
where the address is my local system/the local Xserver, and the port is the appropriate Xserver port ...

is that possible ?

Last edited by chakkerz; 07-06-2004 at 02:29 AM..
chakkerz is offline     Reply With Quote
Old 07-06-2004, 11:33 AM   #2
aaa
Guru
 
Registered: Jul 2003
Location: VA
Distribution: Slack 10.1
Posts: 2,194
Thanked: 0
I don't think it is possible using the docuemented Java classes, you could look at the undocuemented classes in the sun.* packages. As for connecting with a socket, if possible, you would have to worry about implementing the X protocol and all, something Xlib already does (and Java probably uses it under the hood (sun.*)). Plus both of those options are not portable.

Last edited by aaa; 07-06-2004 at 01:56 PM..
aaa is offline     Reply With Quote
Old 07-06-2004, 01:42 PM   #3
jbstew32
Member
 
Registered: Feb 2003
Location: Atlanta, GA
Distribution: Debian 3.1
Posts: 149
Thanked: 0
if im not mistaken, i believe you can create different listeners that will capture keyboard events. Given that say an "h" is pressed, you could store it in an ArrayList, where you can later display the entire arraylist to the screen or write it to a file. I also know there is a similar way of capturing which specific mouse buttons are clicked, or which direction the wheel is scrolled.

The only problem is I am not sure if you can do this without the java program being ran in the forground with the main focus to the user....

I know I am being broad, but it's the best I can do without spending sometime with the API
jbstew32 is offline     Reply With Quote
Old 07-06-2004, 08:41 PM   #4
chakkerz
Member
 
Registered: Dec 2002
Location: Brisbane, Australia
Distribution: Slackware Current, RedHat (RHEL, FC, CentOS), openSuSE, Mac OS X
Posts: 617
Thanked: 0

Original Poster
hmm sun* packages hey?

where do i find info on those?
chakkerz is offline     Reply With Quote
Old 07-07-2004, 08:04 AM   #5
aaa
Guru
 
Registered: Jul 2003
Location: VA
Distribution: Slack 10.1
Posts: 2,194
Thanked: 0
Some googleing turned up this:
http://www.smotricz.com/kabutz/Issue007.html
aaa is offline     Reply With Quote
Old 07-07-2004, 10:27 PM   #6
chakkerz
Member
 
Registered: Dec 2002
Location: Brisbane, Australia
Distribution: Slackware Current, RedHat (RHEL, FC, CentOS), openSuSE, Mac OS X
Posts: 617
Thanked: 0

Original Poster
interesting, thanks will need to try that one ...

PS i found the sun.* packages ... decompress the source code ... duh
chakkerz is offline     Reply With Quote
Old 07-28-2004, 07:58 PM   #7
chakkerz
Member
 
Registered: Dec 2002
Location: Brisbane, Australia
Distribution: Slackware Current, RedHat (RHEL, FC, CentOS), openSuSE, Mac OS X
Posts: 617
Thanked: 0

Original Poster
Incidentally,

I fixed it like so:

I grabbed uberkey 1.2 and get it to pipe it's output to a file, i get my java program to observe the file, and as the file changes it extracts the data.

(i modified ueberkey a little so that my program can extract a little more meaningful data).

I checked the Global Hot Key Listerener, noted by aaa ... alas that only works if the program has focus. Never the less, its a very interesting and useful bit of code, so thanks for that.

Still can't capture the mouse clicks ... but there should be a way
chakkerz is offline     Reply With Quote
Old 07-28-2004, 08:50 PM   #8
mhiggins
Member
 
Registered: Feb 2004
Posts: 140
Thanked: 0
Not sure how "Cross platform" you need this app to be but if you are running some *NIX you could parse the data comming from /dev/mouse, /dev/psaux or /dev/gpmdata .
mhiggins is offline     Reply With Quote
Old 08-06-2004, 08:08 AM   #9
chakkerz
Member
 
Registered: Dec 2002
Location: Brisbane, Australia
Distribution: Slackware Current, RedHat (RHEL, FC, CentOS), openSuSE, Mac OS X
Posts: 617
Thanked: 0

Original Poster
Ahhh ... Interesting I had been considering it, but since no one mentioned that (anywhere), i figured that wasn't a possibility (should have just run cat /dev/psaux i guess ).

Well, it would certainly kill platform independence, but it would give valuable info, in particular mouse clicks ... (since i already jave mouse location).

hmm ... thanks for that, i might have to include that.
chakkerz is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Programming: Java Runtime Environment not found when trying to compile murbz Linux - Software 2 03-26-2009 04:04 AM
Java plugin installed correctly for Firefox but not able to view any java applet tvn Linux - Software 9 10-18-2007 10:03 AM
Web start java not working (java works fine) powadha Debian 5 06-05-2004 01:57 PM
2 Questions: java calling system commands? PERL vs Java? randomx Programming 28 11-28-2003 09:24 PM
Keylogging script/program TomG Programming 3 08-06-2002 04:13 PM


All times are GMT -5. The time now is 02:16 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration