Vighanesh Gursale
Vighanesh Gursale

Reputation: 921

create a thread that will write each character typed using keyboard

I am trying to create a thread that will create a text file and will write each and every character typed on computer using key listener but i am not getting how do i append the created file with next character that user will enter.....might be i am confusing everyone but i just want to store each and every character that user will type (through keyboard)

Its like whenever i execute my application it will create an file and start writing the keychar into that file.

Upvotes: 0

Views: 221

Answers (1)

Jatin
Jatin

Reputation: 31744

The question is a bit unclear. Firstly if you want to to store each and every character typed on system, then is a tough task (explained later). If at all the you want to register the key-strokes with your Java window on top, then you can achieve that, by not closing the file and appending to the same writer.

Hence it will keep appending to it. But make sure, all the key handling occurs inside SwingUtilities.invokeLater().

Now if at all the task, it for any window. Then it is tedious, firstly because you need the OS support for it. You will have to use JNI or preferably JNA. For windows, this will help. I am unclear of which appropriate function to use, but you will find all the desired here (Though you will need to look at win32 api first)

private final User32 lib = = User32.INSTANCE;
//lib.appropriateMethod

Similarly for Mac, using Carbon Framework (deprecated) or Cocoa.

This is the pain, if you do it in Java

Upvotes: 1

Related Questions