I am trying to create a simple Java
Program which implements KeyListener
.
I want to run my program continuously until i abort it or upon a certain condition.
What i wanted to do is after i run the program , whatever keys i pressed , it will get stored in the out.txt
file.
public class StoreInFile implements KeyListener{
public static void main(String[] args) {
while(true){
// **What should i do here such that it will call the keypressed event**.
}
}
@Override
public void keyPressed(KeyEvent e) {
try{
FileWriter fstream = new FileWriter("d:\\out.txt",true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(e.getKeyChar());
out.close();
}catch (Exception ex){
System.err.println("Error: " + ex.getMessage());
}
}
}
Is it possible to achieve in console Application? Basically i want to create a KeyLogger or KeyCatcher. How i can achieve this? Thanks in advance.