Java is the wrong language for the job. you can't perform or catch events outside of the vm your application is running in.
Event handling in keylogger
-
05-07-2023 - |
Вопрос
While thinking of making a keylogger here I learnt how to register listener class
with JFrame
problem with this approach is that it works when JFrame
is in focus otherwise it does not. My question is there any other object with which I can register my listener class and can get the key pressed whether JFrame
was in focus or not.
package javaapplication2;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
public class KeyListenerTest extends JFrame implements KeyListener
{
KeyListenerTest()
{
this.addKeyListener(this);
}
@Override
public void keyTyped(KeyEvent ke) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
System.out.println( ke.getKeyChar() );
}
@Override
public void keyPressed(KeyEvent ke) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void keyReleased(KeyEvent ke) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public static void main(String[] args)
{
KeyListenerTest app = new KeyListenerTest();
app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
app.setSize(500, 500);
//app.setVisible(true);
}
}
Решение
Не связан с StackOverflow