Sunday, September 28, 2014

How to Grab Key Events Outside Java

Instructions

    1

    Open the Java editor that you use to write your code and load up the project you want to edit. Double-click on your Java source code file.

    2

    Add the event handler that detects when a user presses a key. The following Java code detects each key press:

    public boolean mouseDown( Event evt, int x, int y)

    The Java code that you want to execute when the key is pressed is placed within the brackets.

    3

    Add code to the event handler. The following example echoes the keystroke back to the user:

    System.out.println("You pressed the " + evt.key + " key.");



No comments:

Post a Comment