Example usage for java.awt Event KEY_PRESS

List of usage examples for java.awt Event KEY_PRESS

Introduction

In this page you can find the example usage for java.awt Event KEY_PRESS.

Prototype

int KEY_PRESS

To view the source code for java.awt Event KEY_PRESS.

Click Source Link

Document

The user has pressed a normal key.

Usage

From source file:Scribble.java

/** Respond to key presses: Erase drawing when user types 'e' */
public boolean keyDown(Event e, int key) {
    if ((e.id == Event.KEY_PRESS) && (key == 'e')) {
        g.setColor(this.getBackground());
        g.fillRect(0, 0, bounds().width, bounds().height);
        return true;
    } else/*  ww  w .j  a  va  2  s . c om*/
        return false;
}

From source file:EventTester.java

public boolean keyDown(Event e, int key) {
    int flags = e.modifiers;
    if (e.id == Event.KEY_PRESS) // a regular key
        showLine("Key Down: " + mods(flags) + key_name(e));
    else if (e.id == Event.KEY_ACTION) // a function key
        showLine("Function Key Down: " + mods(flags) + function_key_name(key));
    return true;//from   w ww  .j  a  v a2s .co  m
}