-1

Read all the keyboard key pressed values from the system and write into a file, not only from console, entire input from the system like wordpad key press, notpad key press, etc.

newuser
  • 8,338
  • 2
  • 25
  • 33

3 Answers3

1

No, you can't catch keyevents outside the java program.

If you want to do this, you will have to use OS hooks via a C/C++ library.

If you really want to use it in Java, you can still wrap the C code with JNI...

Here is a blog which explains how to do it on Windows.

As we remember, Java allows to catch keyboard events for a key or for a key combination, but this works only if the Java application frame or console is active at this moment, but if the user opens or select antoher window, the keyboard events will not reach our Java application. Each application has own event(message) queue and the keyboard events will be sent into this queue unless the application window(console) is active.

Arnaud Denoyelle
  • 29,980
  • 16
  • 92
  • 148
1

Something like this?

            Scanner sc=new Scanner(System.in);
            String s=sc.nextLine();
            FileWriter fw = new FileWriter("/file.txt");
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(s);
            bw.flush();
            bw.close();
OniTakeda
  • 11
  • 5
-1

The sole purpose of Java running in JVM is to prevent such thing for security reasons. That's why you need C/C++ to write a key logger as Java can't reach outside JVM.

If you want to log keys from your app:

Read more about KeyListeners (javadoc)

And about file writing (example)

Probably duplicate of Listening for input without focus in Java

Community
  • 1
  • 1
Lenymm
  • 879
  • 1
  • 6
  • 27