Example usage for java.awt.event KeyEvent isAltDown

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

Introduction

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

Prototype

public boolean isAltDown() 

Source Link

Document

Returns whether or not the Alt modifier is down on this event.

Usage

From source file:Main.java

private void displayInfo(KeyEvent e, String keyStatus) {

    // You should only rely on the key char if the event
    // is a key typed event.
    int id = e.getID();
    String keyString;// w  w w  .j a  v a 2s  .  com
    if (id == KeyEvent.KEY_TYPED) {
        char c = e.getKeyChar();
        keyString = "key character = '" + c + "'";
    } else {
        int keyCode = e.getKeyCode();
        keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")";
    }

    int modifiersEx = e.getModifiersEx();
    String modString = "extended modifiers = " + modifiersEx;
    String tmpString = KeyEvent.getModifiersExText(modifiersEx);
    System.out.println(e.isAltDown());

    if (tmpString.length() > 0) {
        modString += " (" + tmpString + ")";
    } else {
        modString += " (no extended modifiers)";
    }

    String actionString = "action key? ";
    if (e.isActionKey()) {
        actionString += "YES";
    } else {
        actionString += "NO";
    }

    String locationString = "key location: ";
    int location = e.getKeyLocation();
    if (location == KeyEvent.KEY_LOCATION_STANDARD) {
        locationString += "standard";
    } else if (location == KeyEvent.KEY_LOCATION_LEFT) {
        locationString += "left";
    } else if (location == KeyEvent.KEY_LOCATION_RIGHT) {
        locationString += "right";
    } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) {
        locationString += "numpad";
    } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN)
        locationString += "unknown";
    }

    displayArea.append(keyStatus + newline + "    " + keyString + newline + "    " + modString + newline
            + "    " + actionString + newline + "    " + locationString + newline);
    displayArea.setCaretPosition(displayArea.getDocument().getLength());
}

From source file:KeyNavigateTest.java

protected void processKeyEvent(KeyEvent event) {
    int keycode = event.getKeyCode();

    if (event.isShiftDown())
        speed = FAST_SPEED;/*w w  w.  j  ava  2s.c  om*/
    else
        speed = NORMAL_SPEED;

    if (event.isAltDown())
        altMove(keycode);
    else if (event.isControlDown())
        controlMove(keycode);
    else
        standardMove(keycode);
}

From source file:haven.GameUI.java

public boolean globtype(char key, KeyEvent ev) {
    if (key == ':') {
        entercmd();/* w w  w . j ava 2s .c o  m*/
        return (true);
    } else if (key == ' ') {
        toggleui();
        return (true);
    } else if (key == 3) {
        if (chat.visible && !chat.hasfocus) {
            setfocus(chat);
        } else {
            if (chat.sz.y == 0) {
                chat.resize(chat.savedw, chat.savedh);
                setfocus(chat);
            } else {
                chat.resize(0, 0);
            }
        }
        Utils.setprefb("chatvis", chat.sz.y != 0);
    } else if (key == 16) {
        /*
        if((polity != null) && polity.show(!polity.visible)) {
        polity.raise();
        fitwdg(polity);
        setfocus(polity);
        }
        */
        return (true);
    } else if ((key == 27) && (map != null) && !map.hasfocus) {
        setfocus(map);
        return (true);
    } else if (key != 0) {
        boolean alt = ev.isAltDown();
        boolean ctrl = ev.isControlDown();
        boolean shift = ev.isShiftDown();
        int keycode = ev.getKeyCode();
        if (alt && keycode >= KeyEvent.VK_0 && keycode <= KeyEvent.VK_9) {
            beltwdg.setCurrentBelt(Utils.floormod(keycode - KeyEvent.VK_0 - 1, 10));
            return true;
        } else if (alt && keycode == KeyEvent.VK_S) {
            studywnd.show(!studywnd.visible);
            if (studywnd.visible)
                studywnd.raise();
            return true;
        } else if (alt && keycode == KeyEvent.VK_M) {
            if (mmapwnd != null) {
                mmapwnd.togglefold();
                return true;
            }
        } else if (alt && keycode == KeyEvent.VK_C) {
            craftwnd.show(!craftwnd.visible);
            if (craftwnd.visible)
                craftwnd.raise();
            return true;
        } else if (alt && keycode == KeyEvent.VK_B) {
            buildwnd.toggle();
            if (buildwnd.visible)
                buildwnd.raise();
            return true;
        } else if (alt && keycode == KeyEvent.VK_N) {
            Config.nightvision.set(!Config.nightvision.get());
        } else if (alt && keycode == KeyEvent.VK_G) {
            if (map != null)
                map.gridOverlay.setVisible(!map.gridOverlay.isVisible());
            return true;
        } else if (alt && keycode == KeyEvent.VK_R) {
            if (mmap != null)
                mmap.toggleCustomIcons();
            return true;
        } else if (alt && keycode == KeyEvent.VK_D) {
            if (map != null)
                map.toggleGobRadius();
            return true;
        } else if (alt && keycode == KeyEvent.VK_Q) {
            Config.showQuality.set(!Config.showQuality.get());
            return true;
        } else if (alt && keycode == KeyEvent.VK_K) {
            deckwnd.show(!deckwnd.visible);
            deckwnd.c = new Coord(sz.sub(deckwnd.sz).div(2));
            if (deckwnd.visible)
                deckwnd.raise();
            return true;
        } else if (alt && keycode == KeyEvent.VK_F) {
            if (map != null) {
                map.toggleFriendlyFire();
                msg("Friendly fire prevention is now turned "
                        + (map.isPreventFriendlyFireEnabled() ? "on" : "off"));
            }
            return true;
        } else if (alt && keycode == KeyEvent.VK_I) {
            Config.showGobInfo.set(!Config.showGobInfo.get());
            return true;
        } else if (alt && keycode == KeyEvent.VK_W) {
            Config.screenshotMode = !Config.screenshotMode;
            return true;
        } else if (alt && keycode == KeyEvent.VK_T) {
            Config.disableTileTransitions.set(!Config.disableTileTransitions.get());
            ui.sess.glob.map.rebuild();
            return true;
        } else if (keycode == KeyEvent.VK_Q && ev.getModifiers() == 0) {
            /*
            // get all forageables from config
            List<String> names = new ArrayList<String>();
            for (CustomIconGroup group : ui.sess.glob.icons.config.groups) {
                if ("Forageables".equals(group.name)) {
            for (CustomIconMatch match : group.matches)
                if (match.show)
                    names.add(match.value);
            break;
                }
            }
            tasks.add(new Forager(11 * Config.autopickRadius.get(), 1, names.toArray(new String[names.size()]))); 
            */
            ContextTaskFinder.checkForageables(tasks, ui);
            return true;
        } else if (keycode == KeyEvent.VK_E && ev.getModifiers() == 0) {
            ContextTaskFinder.findHandTask(tasks, ui);
            return true;
        } else if (keycode == KeyEvent.VK_F && ev.getModifiers() == 0) {
            ContextTaskFinder.findBuilding(tasks, ui);
            return true;
        } else if (keycode >= KeyEvent.VK_NUMPAD1 && keycode <= KeyEvent.VK_NUMPAD4) {
            tasks.add(new MileStoneTask(Utils.floormod(keycode - KeyEvent.VK_NUMPAD0 - 1, 10)));
            return true;
        } else if (keycode == KeyEvent.VK_W && ev.getModifiers() == 0) {
            tasks.add(new Drunkard());
            return true;
        } else if (shift && keycode == KeyEvent.VK_I) {
            Config.hideKinInfoForNonPlayers.set(!Config.hideKinInfoForNonPlayers.get());
            return true;
        } else if (ctrl && keycode == KeyEvent.VK_H) {
            Config.hideModeEnabled.set(!Config.hideModeEnabled.get());
            return true;
        } else if (alt && keycode == KeyEvent.VK_P) {
            Config.showGobPaths.set(!Config.showGobPaths.get());
            return true;
        } else if (shift && keycode == KeyEvent.VK_W) {
            if (Config.showQualityMode.get() == 1) {
                Config.showQualityMode.set(2);
            } else {
                Config.showQualityMode.set(1);
            }
            return true;
        } else if (keycode == KeyEvent.VK_TAB && Config.agroclosest.get()) {
            if (map != null)
                map.aggroclosest();
            return true;
        } else if (ctrl && keycode == KeyEvent.VK_F) {
            Config.displayFPS.set(!Config.displayFPS.get());
            return true;
        } else if (keycode == KeyEvent.VK_Z && ev.getModifiers() == 0) {
            tasks.killAllTasks();
            return true;
        } else if (keycode == 192 && ev.getModifiers() == 0) {
            getparent(GameUI.class).menu.wdgmsg("act", "travel", "hearth");
            return true;
        } else if (shift && keycode == KeyEvent.VK_S) {
            HavenPanel.screenshot = true;
            return true;
        }
    }
    return (super.globtype(key, ev));
}

From source file:org.pdfsam.guiclient.commons.panels.JVisualPdfPageSelectionPanel.java

private void initKeyListener() {
    //key listener
    thumbnailList.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if ((e.isAltDown()) && (e.getKeyCode() == KeyEvent.VK_UP)) {
                moveUpButton.doClick();/*from www. j a  va 2  s . c  o m*/
            } else if ((e.isAltDown()) && (e.getKeyCode() == KeyEvent.VK_DOWN)) {
                moveDownButton.doClick();
            } else if ((e.getKeyCode() == KeyEvent.VK_DELETE)) {
                removeButton.doClick();
            } else if (drawDeletedItems && (e.isControlDown()) && (e.getKeyCode() == KeyEvent.VK_Z)) {
                undeleteButton.doClick();
            } else if ((e.isAltDown()) && (e.getKeyCode() == KeyEvent.VK_RIGHT)) {
                rotateButton.doClick();
            } else if ((e.isAltDown()) && (e.getKeyCode() == KeyEvent.VK_LEFT)) {
                rotateAntiButton.doClick();
            }
        }
    });
}

From source file:org.slage.ui.KeyHandler.java

/**
 * Check if the handler should be fired, firing if needed
 * /*from   ww  w .  ja  va  2s .  c  o m*/
 * @param keyEvt
 *            key event
 * @return true if we fired
 */
public boolean fire(KeyEvent keyEvt) {
    if ((iKey == keyEvt.getKeyCode() || iKey == keyEvt.getKeyChar()) && bAlt == keyEvt.isAltDown()
            && bCtrl == keyEvt.isControlDown() && bShift == keyEvt.isShiftDown()) {
        handler.execute();
        return true;
    }
    return false;
}

From source file:tax.MainForm.java

private void dateTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dateTextKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        if (!dateText.getText().equals("")) {
            Util.fadeInAndOut(dateText, Util.darkGreen);

            priceText.setEnabled(true);/*  w  ww. j  ava 2 s .c  o m*/
            priceText.requestFocus();
        } else
            Util.fadeInAndOut(dateText, Util.darkOrange);
    } else if (!evt.isActionKey() && !evt.isAltDown() && !evt.isControlDown() && !evt.isShiftDown()
            && !evt.isMetaDown() && (evt.getKeyCode() != KeyEvent.VK_BACK_SPACE)
            && (evt.getKeyCode() != KeyEvent.VK_DELETE) && (evt.getKeyCode() != KeyEvent.VK_ESCAPE)) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                String text = dateText.getText();
                int dateLength = text.length();

                while (lastDateTextLength == dateLength) {
                    try {
                        Thread.sleep(100);
                        System.out.println("text: " + text);
                        System.out.println(lastDateTextLength + " " + dateLength);
                        return;
                    } catch (InterruptedException ex) {
                        Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    text = dateText.getText();
                    dateLength = text.length();
                }
                try {
                    int num = Integer.decode(text);
                    if (num > 31) {
                        if (text.length() > 0)
                            dateText.setText(text.substring(0, dateLength - 1));
                        else
                            dateText.setText("");
                        return;
                    }
                } catch (Exception e) {
                    if (text.length() > 0)
                        dateText.setText(text.substring(0, dateLength - 1));
                    else
                        dateText.setText("");
                    return;
                }
                lastDateTextLength = dateLength;
            }
        });
    }
}

From source file:tax.MainForm.java

private void priceTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_priceTextKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        if (!priceText.getText().equals("")) {
            Util.fadeInAndOut(priceText, Util.darkGreen);

            afmText.setEnabled(true);/*ww w  .  ja  va 2  s . c  o m*/
            afmText.requestFocus();
        } else
            Util.fadeInAndOut(priceText, Util.darkOrange);
    } else if (!evt.isActionKey() && !evt.isAltDown() && !evt.isControlDown() && !evt.isShiftDown()
            && !evt.isMetaDown() && (evt.getKeyCode() != KeyEvent.VK_BACK_SPACE)
            && (evt.getKeyCode() != KeyEvent.VK_DELETE) && (evt.getKeyCode() != KeyEvent.VK_ESCAPE)) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                String text = priceText.getText();
                int priceLength = text.length();

                while (lastPriceTextLength == priceLength) {
                    try {
                        Thread.sleep(100);
                        System.out.println("text: " + text);
                        System.out.println(lastPriceTextLength + " " + priceLength);
                        return;
                    } catch (InterruptedException ex) {
                        Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    text = priceText.getText();
                    priceLength = text.length();
                }

                //                    if (text.charAt(priceLength - 1) == '\u002c')
                //                        priceText.setText(text.substring(0, priceLength - 1) + ".");

                try {
                    Double.parseDouble(text);
                } catch (Exception e) {
                    if (text.length() > 0) {
                        //                            System.out.println(text.charAt(priceLength - 1));
                        priceText.setText(text.substring(0, priceLength - 1));
                    } else
                        priceText.setText("");
                    return;
                }
                lastPriceTextLength = priceLength;
            }

        });
    }
}

From source file:tax.MainForm.java

private void afmTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_afmTextKeyPressed
    String text = afmText.getText();

    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        if (text.length() == 9) {

            for (Object key : afmToName.keySet()) {
                if (afmToName.get(key).equals(text))
                    nameText.setText(key.toString());
            }//from   w w  w. j a  v a  2s  .  com

            //                Util.fadeInAndOut(afmText, Util.darkGreen);
            addRowBut.doClick();
        } else if (text.length() == 0) {
            Util.fadeInAndOut(afmText, Color.white);
            nameText.setEnabled(true);
            nameText.requestFocus();
        } else
            Util.fadeInAndOut(afmText, Util.darkOrange);
    } else if (!evt.isActionKey() && !evt.isAltDown() && !evt.isControlDown() && !evt.isShiftDown()
            && !evt.isMetaDown() && (evt.getKeyCode() != KeyEvent.VK_BACK_SPACE)
            && (evt.getKeyCode() != KeyEvent.VK_DELETE) && (evt.getKeyCode() != KeyEvent.VK_ESCAPE)) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                String text = afmText.getText();
                int afmLength = text.length();

                while (lastAFMTextLength == afmLength) {
                    try {
                        Thread.sleep(100);
                        System.out.println("text: " + text);
                        System.out.println(lastAFMTextLength + " " + afmLength);
                        return;
                    } catch (InterruptedException ex) {
                        Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    text = afmText.getText();
                    afmLength = text.length();
                }

                try {
                    int num = Integer.decode(text);
                    if (afmLength > 9) {
                        if (text.length() > 0)
                            afmText.setText(text.substring(0, afmLength - 1));
                        else
                            afmText.setText("");
                        return;
                    }
                } catch (Exception e) {
                    if (text.length() > 0)
                        afmText.setText(text.substring(0, afmLength - 1));
                    else
                        afmText.setText("");
                    return;
                }

                lastAFMTextLength = afmLength;
            }
        });
    }
}

From source file:tax.MainForm.java

private void afmTextSKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_afmTextSKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        String text = afmTextS.getText();

        if (text.length() == 9) {
            try {
                int num = Integer.parseInt(text);
            } catch (Exception e) {
                afmTextS.setText("");
                return;
            }//from  w  ww  .j a  v  a 2  s  .  c o  m

            //                Util.fadeInAndOut(afmTextS, Util.darkGreen);
            addNameBut.doClick();
        } else {
            Util.fadeInAndOut(afmTextS, Util.darkOrange);
        }
    } else if (!evt.isActionKey() && !evt.isAltDown() && !evt.isControlDown() && !evt.isShiftDown()
            && !evt.isMetaDown() && (evt.getKeyCode() != KeyEvent.VK_BACK_SPACE)
            && (evt.getKeyCode() != KeyEvent.VK_DELETE) && (evt.getKeyCode() != KeyEvent.VK_ESCAPE)) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                String text = afmTextS.getText();
                int afmLength = text.length();

                while (lastAFMTextSLength == afmLength) {
                    try {
                        Thread.sleep(100);
                        System.out.println("text: " + text);
                        System.out.println(lastAFMTextSLength + " " + afmLength);
                        return;
                    } catch (InterruptedException ex) {
                        Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    text = afmTextS.getText();
                    afmLength = text.length();
                }

                try {
                    int num = Integer.decode(text);
                    if (afmLength > 9) {
                        if (text.length() > 0)
                            afmTextS.setText(text.substring(0, afmLength - 1));
                        else
                            afmTextS.setText("");
                        return;
                    }
                } catch (Exception e) {
                    if (text.length() > 0)
                        afmTextS.setText(text.substring(0, afmLength - 1));
                    else
                        afmTextS.setText("");
                    return;
                }

                lastAFMTextSLength = afmLength;
            }
        });
    }
}