0

Is there any way to write a Java program to find the values of keys pressed without using applet or swings or awt.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • 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 Answers1

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) {
    }
});