Example usage for java.awt.event KeyEvent getKeyCode

List of usage examples for java.awt.event KeyEvent getKeyCode

Introduction

In this page you can find the example usage for java.awt.event KeyEvent getKeyCode.

Prototype

public int getKeyCode() 

Source Link

Document

Returns the integer keyCode associated with the key in this event.

Usage

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    int keyCode = evt.getKeyCode();
    int d;//ww  w  .j a  va2  s .co m
    if (evt.isShiftDown()) {
        System.out.println("shift down");
    }
    if (keyCode == KeyEvent.VK_LEFT)
        System.out.println("KeyEvent.VK_LEFT");
    else if (keyCode == KeyEvent.VK_RIGHT)
        System.out.println("KeyEvent.VK_RIGHT");
    else if (keyCode == KeyEvent.VK_UP)
        System.out.println("KeyEvent.VK_UP");
    else if (keyCode == KeyEvent.VK_DOWN)
        System.out.println("KeyEvent.VK_DOWN");
}

From source file:Main.java

public void keyReleased(KeyEvent arg0) {
    System.out.println("Key Released " + arg0.getKeyCode());
}

From source file:mainDraw.java

public void keyReleased(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_RIGHT)
        draw.moveRight();//from  w w w. j  av  a  2 s. c o  m
    else if (e.getKeyCode() == KeyEvent.VK_LEFT)
        draw.moveLeft();
    else if (e.getKeyCode() == KeyEvent.VK_DOWN)
        draw.moveDown();
    else if (e.getKeyCode() == KeyEvent.VK_UP)
        draw.moveUp();

}

From source file:Main.java

public void keyPressed(KeyEvent evt) {
    int keyCode = evt.getKeyCode();
    int d;/*from  w w w . j  a  va  2  s.co m*/
    if (evt.isShiftDown())
        d = 5;
    else
        d = 1;
    if (keyCode == KeyEvent.VK_LEFT)
        add(-d, 0);
    else if (keyCode == KeyEvent.VK_RIGHT)
        add(d, 0);
    else if (keyCode == KeyEvent.VK_UP)
        add(0, -d);
    else if (keyCode == KeyEvent.VK_DOWN)
        add(0, d);
}

From source file:Main.java

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    if (comboList == null) {
        comboList = list;/*  w w w  .ja  v  a 2s .  co m*/
        KeyAdapter listener = new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) {
                    int x = 5;
                    int y = comboList.indexToLocation(comboList.getSelectedIndex()).y;
                    System.out.println(comboList.getSelectedIndex());
                }
            }
        };
        combo.addKeyListener(listener);
        combo.getEditor().getEditorComponent().addKeyListener(listener);
    }
    if (isSelected) {
        System.out.println(value.toString());
    }
    return this;
}

From source file:UndoableTextArea.java

public void keyPressed(KeyEvent e) {
    if ((e.getKeyCode() == KeyEvent.VK_Z) && (e.isControlDown())) {
        try {/* w  ww.j av  a  2s .  c  om*/
            m_undoManager.undo();
        } catch (CannotUndoException cue) {
            Toolkit.getDefaultToolkit().beep();
        }
    }

    if ((e.getKeyCode() == KeyEvent.VK_Y) && (e.isControlDown())) {
        try {
            m_undoManager.redo();
        } catch (CannotRedoException cue) {
            Toolkit.getDefaultToolkit().beep();
        }
    }
}

From source file:Drums.java

public Drums(Synthesizer synth) {
    super("Drums");

    // Channel 10 is the GeneralMidi percussion channel. In Java code, we
    // number channels from 0 and use channel 9 instead.
    channel = synth.getChannels()[9];//from ww w .  j a v  a2  s.  co  m

    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81) {
                channel.noteOn(key, velocity);
            }
        }

        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81)
                channel.noteOff(key);
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(MouseEvent e) {
            velocity = e.getX();
        }
    });
}

From source file:Main.java

public Main(Synthesizer synth) {
    super("Drums");

    // Channel 10 is the GeneralMidi percussion channel. In Java code, we
    // number channels from 0 and use channel 9 instead.
    channel = synth.getChannels()[9];/*from   w ww .j a  v a 2  s  . co m*/

    addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81) {
                channel.noteOn(key, velocity);
            }
        }

        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key >= 35 && key <= 81)
                channel.noteOff(key);
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseMoved(MouseEvent e) {
            velocity = e.getX();
        }
    });
}

From source file:TextLayoutWithCarets.java

public TextLayoutWithCarets() {
    addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent ke) {
            if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {
                mHit = mLayout.getNextRightHit(mHit.getInsertionIndex());
                if (mHit == null)
                    mHit = mLayout.getNextLeftHit(1);
                repaint();//from   ww  w  .  j  av  a  2  s. c om
            } else if (ke.getKeyCode() == KeyEvent.VK_LEFT) {
                mHit = mLayout.getNextLeftHit(mHit.getInsertionIndex());
                if (mHit == null)
                    mHit = mLayout.getNextRightHit(mLayout.getCharacterCount() - 1);
                repaint();
            }
        }

        public void keyTyped(KeyEvent arg0) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent arg0) {
            // TODO Auto-generated method stub

        }
    });

}

From source file:org.jcurl.core.gui.SimpleKeys.java

public void keyPressed(KeyEvent e) {
    switch (e.getKeyCode()) {
    case KeyEvent.VK_SPACE:
        if (worker == null || !worker.isAlive()) {
            worker = new Thread(player, player.getClass().getName());
            worker.start();//from  w  w  w  .j  av a2 s.  c o m
        } else {
            worker.interrupt();
            worker = null;
        }
        break;
    case KeyEvent.VK_LEFT:
        player.setTimeScale(-1);
        break;
    case KeyEvent.VK_RIGHT:
        player.setTimeScale(1);
        break;
    }
}