I need to create a program which fire event on every key press(like key logger). I couldn’t able to get key value. This program will run behind and on every key press it fire event. I didn’t find any thing related to this on net.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is very strange that you cannot find anything.
You should user
KeyListenerto log key events. If only one event (e.g. keyUP, keyDown or keyPress) is relevant useKeyAdapterinstead.The problem is that key listener can be attached to any java screen element and catches events dispatched to this element only. For example you can create Frame and add key listener to it and capture all key events withing this frame.
You cannot capture key events outside the java application.
If you still want to do this you can use the following work-around. Create transparent window and add listener to it. The listener should catch events, log them and then imitate them on the same location on screen using
java.awt.Robot.This reference will help you to create transparent window: http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html
Other way is to use JNI/JNA directly or indirectly. For example xdotools can help you.