Java Keyboard Logger

Source: Internet
Author: User
Tags stub

Main.java:

Import Java.awt.BorderLayout;
Import Java.awt.GridLayout;
Import java.awt.event.ActionEvent;
Import Java.awt.event.ActionListener;
Import Java.io.BufferedReader;
Import Java.io.FileReader;
Import java.io.IOException;

Import Javax.swing.JButton;
Import Javax.swing.JFrame;
Import Javax.swing.JLabel;
Import Javax.swing.JPanel;
Import Javax.swing.JRootPane;
Import Javax.swing.JScrollPane;
Import Javax.swing.JTextArea;
Import javax.swing.WindowConstants;

Class Main {

public static void Main (final string[] args) {//TODO auto-generated method stub final Recorder R = new Recorder (); final thread thread = new  Thread (R); Thread.setdaemon (true); final BorderLayout BL = new BorderLayout (); final GridLayout GL = new GridLayout (); final JFrame JF = new JFrame ("Jkeyrecorder Console"), final JButton JB = new JButton ("Start recording"), final JButton JB2 = new JButton ("Stop Final JButton JB3 = new JButton ("View results"), final JPanel JP = new JPanel (); final JLabel JL = new JLabel ("Keylogger File location:/var/lo G/jkeyrecorder.log "); Jb2.setenabled (FALSE); Jf.setlayout (BL); Jp.setlayout (GL); Jp.add (JB); Jp.add (JB2); Jp.add (JB3); Jf.add (JP, Borderlayout.center); Jf.add (JL, Borderlayout.south); Jf.setundecorated (TRUE); Jf.setsize (500, 500); Jf.getrootpane (). Setwindowdecorationstyle (Jrootpane.plain_dialog); Jf.setdefaultcloseoperation (Windowconstants.exit_on_close); Jf.setlocationrelativeto (NULL); Jf.setvisible (TRUE);    Jb.addactionlistener (new ActionListener () {@Override public void actionperformed (final actionevent arg0) {TODO Auto-generated method stub jb.setenabled (false);    Jb2.setenabled (TRUE);    Jl.settext (Jl.gettext () + "(in operation)");    Jb3.setenabled (FALSE);    Jf.getrootpane (). Setwindowdecorationstyle (Jrootpane.none);    Thread.Start (); }}); Jb2.addactionlistener (new ActionListener () {@Override public void actionperformed (final actionevent arg0) {//T    ODO Auto-generated method stub jb2.setenabled (false);    Jb3.setenabled (TRUE);    Jb.setenabled (TRUE);    Jf.getrootpane (). Setwindowdecorationstyle (Jrootpane.plain_dialog);    Thread.Interrupt ();    Jl.settext ("Keylogger File location:/var/log/jkeyrecorder.log"); }}); Jb3.addactionlistener (new ActionListener () {@Override public void actionperformed (final actionevent arg0) {//T    ODO automatically generated method stub final JFrame JF2 = new JFrame ("Jkeyrecorder-record result");    Final JScrollPane JSP = new JScrollPane ();    Final JTextArea JTA = new JTextArea ();    Jsp.setviewportview (JTA);    Jf2.setsize (725, 725);    Jf2.setlocationbyplatform (TRUE); Jf2.getrootpane (). SetwindowdecorationstYLE (Jrootpane.frame);    Jf2.setundecorated (TRUE);    Jf2.setdefaultcloseoperation (Windowconstants.dispose_on_close);    Jf2.add (JSP);    Jta.seteditable (FALSE);        try {final FileReader FR = new FileReader ("/var/log/jkeyrecorder.log");        Final BufferedReader BR = new BufferedReader (FR);        String s;        while ((s = br.readline ()) = null) {jta.append (s);        } fr.close ();    Br.close ();    } catch (Final IOException e) {//TODO auto-generated catch block E.printstacktrace ();    } jf2.setvisible (True); }});}

}
Recorder.java:

Import java.awt.event.KeyEvent;
Import Java.awt.event.KeyListener;
Import Java.io.File;
Import Java.io.FileWriter;
Import java.io.IOException;

Class Recorder implements Runnable {

@Overridepublic void run() {// TODO 自动生成的方法存根final File F = new File("/var/log/JKeyRecorder.log");if (F.exists() == false) {    try {    Runtime.getRuntime().exec("touch " + F.getAbsolutePath());    } catch (final IOException e) {    // TODO 自动生成的 catch 块    e.printStackTrace();    }}new KeyListener() {    @Override    public void keyPressed(final KeyEvent arg0) {    // TODO 自动生成的方法存根    final int keycode = arg0.getKeyCode();    final String keytext = KeyEvent.getKeyText(keycode);    try {        final FileWriter FW = new FileWriter(F);        FW.append(keytext);    } catch (final IOException e) {        // TODO 自动生成的 catch 块        e.printStackTrace();    }    }    @Override    public void keyReleased(final KeyEvent arg0) {    // TODO 自动生成的方法存根    }    @Override    public void keyTyped(final KeyEvent arg0) {    // TODO 自动生成的方法存根    }};}

}

I wrote it into two *.java files.
But it does not seem to record input from the keyboard.
I checked, looks like KeyListener only applies to GUI?
If that's the case, I'm going to do an instant keylogger that runs in the background.
If you use only keyevent, then all the records are numeric keys, not the characters on the keyboard keys.
[Email protected]:~# cat/var/log/jkeyrecorder.log
[Email protected]:~#
The JKeyRecorder.log is empty.

Java Keyboard Logger

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.