Is there any way to write a Java program to find the values of keys pressed without using applet or swings or awt.
Asked
Active
Viewed 42 times
0
-
just to understand your question better. Is there a reason or just a general questions? – WiPU Jul 16 '19 at 13:35
-
@Manikandan - are you looking for a system wide keyboard listener for a non-graphical application? If yes, this question is probably a duplicate of https://stackoverflow.com/questions/16179923/how-to-capture-global-key-presses-in-java – Vlad Topala Jul 16 '19 at 13:51
-
Why not AWT? What can you use? SWT? Android APIs? – Stephen C Jul 16 '19 at 14:57
1 Answers
0
Take a look at java.awt.event.KeyListener
Your code should look something like this:
f.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key pressed code=" + e.getKeyCode() + ", char=" + e.getKeyChar());
}
@Override
public void keyReleased(KeyEvent e) {
}
});
-
Unfortunately this uses `awt` and not using it is one of the question's requirements – Vlad Topala Jul 16 '19 at 13:50