Check out example codes for "how to add a keylistener to a jframe". It will help you in understanding the concepts better.

Code Example 1

System.out.println("test");
frame.addKeyListener(new KeyListener() {
    public void keyPressed(KeyEvent e) { System.out.println( "tester"); }

    public void keyReleased(KeyEvent e) { System.out.println("2test2"); }

    public void keyTyped(KeyEvent e) { System.out.println("3test3"); }
});

Learn ReactJs, React Native from akashmittal.com