listening to keyboard events
An expert advise needed:
my program should listen to all keyboard events and record them.
1) I don't know how to organise listening not through Swing (or any GUI component), but somehow directly.
2) I don't know how to listen to the events when my program is 'focused' out.
3) maybe its better idea to write in C++
thanks for any help
1: Check out the KeyListener interface
2: Your program can't listen to anything when it is focused out, maybe write some code
that the program can execute when nobody is using it ?
As fopr java components, use the requestFocus method.
3: Yes, if you know nada about the java listener concept and you don't have to do it in java. But if you have to do it in java I think you would be better off with some
sun documentation & tutorials first.
thanks for reply, sjalle!
have already checked the KeyListener, it works fine when listens to the keyboard events through the GUI elements (e.g. Textfield), so both - my programm must be focused and the GUI component must be focused to get the event. My aim is to get keybord events with my programm e.g. while writing word document... or writing a password in internet bank
so at the moment I don't see the solution in JAVA, but I see it in C++, quite complicated for me though, but won't give up
I can imagine intercepting ms-word keystrokes may be difficult. I honestly cannot
think of any way of doing that with java unless you somehow managed to 'wrap'
your textprocessor in java, and fed it the keystrokes through your application, or
an operating system hack (I'm talking windows now..)/some assembler snipped
between the keyboard feed and the OS......
I suppose that all you need is the system keyboard hook...
You can check http://www.jniwrapper.com/winpack_features.jsp#hooks
This solution allows to track (and record if necessary _all_ keyboard events from your Java application without the native code.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center