Exiting programs using the escape key

My team and I are design games for autistic children. One of the problems we are having is that we do not know how to quit the application using the escape key. Our team would really appreciate it if you could tell us how this is done.

Quick example:
import java.awt.event.*;
import javax.swing.*;
public class ExitOnEscape extends JFrame
    public ExitOnEscape()
        setSize(300, 300);
        addKeyListener(new KeyAdapter()
            public void keyPressed(KeyEvent e)
                int key = e.getKeyCode();
                if(key == KeyEvent.VK_ESCAPE)
                    System.exit(0);
        setVisible(true);
    public static void main(String[] args)
        new ExitOnEscape();
}

Similar Messages

  • Using the Escape key in simulations and assessments

    I have recently recorded a simulation/assessment that needs to use the Escape key to close a pop-up window and returns to the main application window. The recording has not been an issue; however, using Escape with failure messages is proving to be tricky.  Here's what I have discovered while resording my sim/assess, along with my questions:
    When I press Escape, Captivate captures this keystroke as a shortcut attached to a Click Box. This works on the assessment side, but fails to produce a failure message on the assessment side when the user does not press the Escape key.
    I need to produce a failure message when the user  does not press Escape.
    Can I storethe unicode value of Escape in a TEB variable and then use an if . . . else statement to either advance to the next slide (success action) or produce a caption that mimics a failure caption?  If so, how would I write this item?
    Could I use a Loss of focus trigger instead?
    Does Captivate have a variable that records a unicode value (Something like CPKeyPressedValue"?
    Are there any other alternatives?

    In the case of buttons and clickbox objects, where clicking is allowed, the failure is normally registered when the user CLICKS OUTSIDE the button or click box.  The evaluation of Success/Fail happens on the click.
    In the case of a Text Entry Box, the interactivity is all about what the user enters into the text field and whether or not it is correct/incorrect when compared to approved answer text.  The main purpose of the TEB object is not centered on the clicking of the button that accompanies the text field.  The button just provides a way to trigger the Success/Failure evaluation of the user interaction with the text field.
    Since you have deselected Allow Mouse Click for your click box, you've effectively made it mandatory to use keystrokes to trigger the Success/Failure evaluation of the object. So clicking outside the box is no longer going to do anything because Allow Mouse Click is off.  You'll get a failure message on this click box now for many (but not all) keystrokes that are not the one assigned.
    By the way, using the Escape key as a keystroke if you Preview the project in Captivate just shuts down the preview (as you've probably already found out).

  • Why can't I close a message once I've read it using the Escape key anymore

    Until recently I have been able to close a message, once read, with the ESCAPE key but this does not seem to work any more.
    Any thoughts on how to fix this?
    WIN7 professional
    Thunderbird 24.6.0
    Thanks
    Geoff

    '''Ctrl + W''' are the keys to close an open tab.
    There is an addon which uses Esc key.
    * https://addons.mozilla.org/en-us/thunderbird/addon/close-tab-on-esc/

  • Using the Alt key and numeric code from Character Map to insert special characters in Office 2010 programs

    I am used to using the ALT key and specific numbers for characters from the Character Map to place characters in Office programs like Outlook, Word, Excel. I have a new Lenovo T530 Laptop running the Windows 7 Professional Operating System. I have MS Office
    2010 Home and Business. In previous versions of Office, this feature worked first time, every time. On this machine, it is a 'no go' situation. Lenovo tech support says it is a Microsoft issue and Microsoft says it is a Lenovo issue. Either way, I'm having
    difficulty resolving the issue and getting this wonderful featrure working for me. Any suggestions and guidance would really be appreciated. Thank you. 

    Hi,
    Haven't been verified this myself, but since this feature require to use the numeric keypad to input the value, I suspect the cause of the issue is the laptop keyboard.
    To workaround this issue, try enable the numeric keypad from your laptop keyboard, normally, we can enable it by press
    Fn + Num Lock.
    After that, try insert characters again.
    Max Meng
    TechNet Community Support

  • When I hit the escape key to close out the open file dialog box, firefox hangs or crashes.

    When I open the "open file" dialog box using the ctrl+O and then hit the escape key to exit the box, I get an error message which I'm not able to paste here.
    it says something about a runtime problem and if I try the same thing again to reproduce the problem, it will sometimes just hang and windows vista will tell me the program is not responding.
    I've checked to see if there are any crash IDs but none were found for this time frame.
    I have even disabled all add ons.
    I'm currently using vista 64 bit edition and Firefox 6, beta edition.

    Hi,
    Please also try right-clicking on the link corresponding to the language version and '''Save Target As''' to save the Firefox installer. If the problem persists, posting [http://answers.microsoft.com/ here] would also be helpful.
    [https://www.mozilla.org/en-US/firefox/all.html Firefox Latest]

  • How do I get JWindow to respond to the escape key

    Hi,
    I am using JWindow to display an animation program and I want the user to press the "escape" key to end the program. But the program is not responding to any key events. Please help. Below is the code. Thanx.
    public Class DrawPolygons extends JWindow implements KeyListener()
    public void keyPressed(KeyEvent e)
    if(e.getKeyCode() == e.VK_ESCAPE)
    System.exit(0);
    public void keyTyped(KeyEvent e){}
    public void keyReleased(KeyEvent e){}

    My program uses the "Random class" to obtain points to draw polygons. At the beginning of the program I use JOptionPane to obtain the seed to generate the random numbers.
    If I press the "esc" key when the JOptionPane pops-up, the program ends but if I press the key when the polygons are being drawn, the program doesn't end. I am wondering, does it have to do with JWindow, or J2SDK_1.4.01 or could it be because I am using a timer that paints the shapes at a certain time interval? I don't understand. I will appreciate your suggestions, Takis. Thanx.
    Bemmah

  • Default behaviour of the Escape key while editing a cell in JTable??

    Hi all,
    i have a Jtable which get its data from an own model object which extends DefaultTableModel.
    If i overwrite the isCellEditable(row, col) method within the tablemodel object and set a specific column to editable, then i notice while editing a cell in that column that the default behaviour of the Escape key is that independet from what you have entered before in to the cell the editing stops and the cell gets the value it had before editing.
    This is the case for me even if i apply a custom editor to a column (one that extends DefaultCellEditor). It is just a JTextField that limits the number of digits a user can enter. Everything works fine. If the user edits the cell and presses ENTER or the "down arrow key" i can check what he has entered with the help of the getCellEditorValue() method. But if the user hits the ESC key after editing a cell this method is not invoked!!!
    My question is :
    is there any way to detect that the user cancels editing with the ESC-key.
    this is very important for me because if the user goes editing the cell i lock the related record in the database, if i cannot detect this it is locked till the application terminates.
    Thanks for any help in advance

    I try override the JTable editingCanceled() ==> does not work.
    I try the addCellEditorListener( CellEditorListener l ) ==> does not work.
    Finally, I try the addKeyListener ==> it works.
    Here is a quick demo. program:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class Test {
    public static void main(String[] args){
    JFrame f = new JFrame();
    String[] colName = {"a", "b"};
    String[][] rowData = {{"1", "2"}, {"3", "4"}};
    JTable table = new JTable(rowData, colName);
    JTextField t = new JTextField(10);
    t.setBackground(Color.red);
    t.addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
    // do what ever you want ex. un-lock table
    System.out.println("ESCAPE");
    DefaultCellEditor editor = new DefaultCellEditor(t);
    TableColumnModel colModel = table.getColumnModel();
    for (int i = colModel.getColumnCount()-1; i >= 0; i--) {
    colModel.getColumn(i).setCellEditor(editor);
    f.setContentPane(new JScrollPane(table));
    f.pack();
    f.setVisible(true);

  • Key Bindings using the arrow keys

    Following is some code that allows you to move a component around the screen using the arrow keys. I've noticed a problem and I'm just wondering if its Java or my keyboard.
    Lets start with an example that works:
    Press the down and right keys. Then press either the up or left key. The image moves proving that it supports 3 keys.
    Now for the problem:
    Press the up and left keys. Then press either the down or right key. Three things to notice:
    a) the direction doesn't change when the third key is pressed
    b) no output is displayed, so the ActionListener is not being invoked
    c) after a short time, the program starts beeping
    Now try rerunning the code after removing the comments that assign the key bindings to the "a, s, d, f" keys. Redo the above test and it works even if all four keys are pressed.
    I don't remember this problem when I wrote the code a while ago, but I did recently get a cheap new keyboard so I'm just wondering if the problem is my keyboard or whether its a quirk with Java.
    You can download Duke from here:
    http://java.sun.com/docs/books/tutorial/uiswing/examples/components/LayeredPaneDemoProject/src/components/images/dukeWaveRed.gif
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class KeyboardNavigationProblem implements ActionListener
         private JComponent component;
         private int deltaX;
         private int deltaY;
         private Timer timer;
         private int keysPressed;
         private InputMap inputMap;
         public KeyboardNavigationProblem(JComponent component, int delay)
              this.component = component;
              this.deltaX = deltaX;
              this.deltaY = deltaY;
              timer = new Timer(delay, this);
              timer.setInitialDelay( 0 );
              inputMap = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
         public void addAction(int keyCode, String description, int deltaX, int deltaY)
              new NavigationAction(keyCode, description, deltaX, deltaY);
         public void updateDeltaX(int delta)
              deltaX += delta;
         public void updateDeltaY(int delta)
              deltaY += delta;
         public void actionPerformed(ActionEvent e)
              int componentWidth = component.getSize().width;
              int componentHeight = component.getSize().height;
              Dimension parentSize = component.getParent().getSize();
              int parentWidth  = parentSize.width;
              int parentHeight = parentSize.height;
              //  Determine next X position
              int nextX = Math.max(component.getLocation().x + deltaX, 0);
              if ( nextX + componentWidth > parentWidth)
                   nextX = parentWidth - componentWidth;
              //  Determine next Y position
              int nextY = Math.max(component.getLocation().y + deltaY, 0);
              if ( nextY + componentHeight > parentHeight)
                   nextY = parentHeight - componentHeight;
              //  Move the component
              component.setLocation(nextX, nextY);
         class NavigationAction extends AbstractAction implements ActionListener
              private int deltaX;
              private int deltaY;
              private KeyStroke pressedKeyStroke;
              private boolean listeningForKeyPressed;
              public NavigationAction(int keyCode, String description, int deltaX, int deltaY)
                   super(description);
                   this.deltaX = deltaX;
                   this.deltaY = deltaY;
                   pressedKeyStroke = KeyStroke.getKeyStroke(keyCode, 0, false);
                   KeyStroke releasedKeyStroke = KeyStroke.getKeyStroke(keyCode, 0, true);
                   inputMap.put(pressedKeyStroke, getValue(Action.NAME));
                   inputMap.put(releasedKeyStroke, getValue(Action.NAME));
                   component.getActionMap().put(getValue(Action.NAME), this);
                   listeningForKeyPressed = true;
              public void actionPerformed(ActionEvent e)
                   if (listeningForKeyPressed)
                        updateDeltaX( deltaX );
                        updateDeltaY( deltaY );
                        inputMap.remove(pressedKeyStroke);
                        listeningForKeyPressed = false;
                           if (keysPressed == 0)
                                timer.start();
                     keysPressed++;
                   else // listening for key released
                        updateDeltaX( -deltaX );
                        updateDeltaY( -deltaY );
                        inputMap.put(pressedKeyStroke, getValue(Action.NAME));
                        listeningForKeyPressed = true;
                        keysPressed--;
                           if (keysPressed == 0)
                                timer.stop();
                   System.out.println(KeyboardNavigationProblem.this.deltaX + " : "
                   + KeyboardNavigationProblem.this.deltaY);
         public static void main(String[] args)
              JPanel contentPane = new JPanel();
              contentPane.setLayout( null );
              JLabel duke = new JLabel( new ImageIcon("dukewavered.gif") );
              duke.setSize( duke.getPreferredSize() );
              duke.setLocation(100, 100);
              contentPane.add( duke );
              KeyboardNavigationProblem navigation = new KeyboardNavigationProblem(duke, 100);
              navigation.addAction(KeyEvent.VK_LEFT, "zLeft", -5, 0);
              navigation.addAction(KeyEvent.VK_RIGHT, "zRight", 5, 0);
              navigation.addAction(KeyEvent.VK_UP, "zUp", 0, -5);
              navigation.addAction(KeyEvent.VK_DOWN, "zDown", 0, 5);
    //          navigation.addAction(KeyEvent.VK_A, "zLeft", -5, 0);
    //          navigation.addAction(KeyEvent.VK_S, "zRight", 5, 0);
    //          navigation.addAction(KeyEvent.VK_D, "zUp", 0, -5);
    //          navigation.addAction(KeyEvent.VK_F, "zDown", 0, 5);
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.setContentPane( contentPane);
              frame.setSize(800, 600);
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

    if you hold down left and right (so it doesn't move), down works, but not up.
    hold up/down, right works but not left.Yes, the problem only seems to be when the up and left in combination with the right or down key is pressed.
    num lock off - use the number pad arrow keys and all works OK Thats interesting, I didn't notice that. Although it just confuses the issue as to what the problem is.
    So it appears to me that:
    a) left + up + down, and
    b) left + up + right
    are special key combinations that are intercepted by either the OS or the JVM. Do these key combinations ring a bell to anybody?
    I'm use JDK1.4.2 on XP. I wonder if other OS will have the same problem?
    Again, this isn't a real, problem, just more of a curiosity. Thanks,

  • HT1338 My MacBook Pro (running Leopard 10.5.8) won't allow keyboard to type an upper case 'C' using the shift key...works fine with caps lock, or, with my Typinator workaround using double-typed lower case c (not always best). Any ideas?

    My MacBook Pro keyboard won't type an upper case 'C' using the shift key... only with caps lock. Workaround has been to use Typinator by typing a double lower case c, not always the best solution. Mac is a refurbished model, which initially was fine. Apple tech helped me correct the quirk when it first appeared, but now it has returned and refuses fixes. Any ideas?

    I'm willing to bet that this has something to do with iCloud.  I've been facing a frozen computer nearly every time I go into it. 
    In Activity Monitor I have seen two programs associate with iCloud that take up about 2.5 GB of memory (I only have 4 in the computer) -- causing everything to freeze.  One of these is called "iCloud Helper" and the other one is something like "Address Book Sync helper" -- I see parts of these names in the stuff you have posted.
    I am at my wits' end with these and have written to Apple asking them to do away with these or fix them.  To get rid of the Address book sync thing I have gone into system preferences for iCloud and unchecked Contacts -- but then spontaneously it gets rechecked.  And oftentimes after I Force Quit the iCloud helper, it spontaneously turns on again.  My conclusion --- the iCloud is basically unusable.  It turns a Mac into the most useless, clogged, sluggish PC.  If this is happening to a lot of people's computers -- and I see no reason why yours or mine should be an exception -- these programs just might destroy Apple itself. 
    So -- I'm about to completely give up on iCloud, and I suspect that others will too unless this gets fixed.
    Cheers,
    Bob

  • Using the Tab Key in Simulations

    Hi, I am new to this forum and new to Captivate 5.
    I am creating online courses that teach people how to use our company's software programs so I use Captivate simulations often.  We use Captivate to record the simulations and then we use Articulate Presenter to create the course.
    Problem 1
    I still can't figure out how to use Tabs smoothly with Text Entry boxes all together. I've been reading all of the forum information and trying everything and the Tab won't work correctly for me.
    I have only placed one TEB on a slide but when I get to the second TEB on the next slide, I start typing the text and the system moves forward to the next action before I finish typing the text. Or, I have to press the Tab key twice to get to the next TEB on the next slide. I am totally confused.
    Problem 2
    I have been able to successfully create a simulation using the Enter key to validate text entry boxes.  I publish the simulation and use the swf file to create a web object that gets placed in Articulate. The web object holds the swf file and the html file below.
    Here is an example of the html file:
    This works just fine when I use the Enter key to validate text entry boxes. However, we decided to use the Tab key and now I have to deal with the seamless tabbing issues in Captivate. I figured out how to add the seemless tab info to the published file, Can I use the Captivate html file to create a web object? If so, how do I do that?
    Please help!!

    I have had success using TAB in Captivate 5.
    I learned:
    Dont put Text Entry Boxes on the timeline appearing at 0 seconds. Have them appear at 0.2. This gives it time to load.
    Make sure they are on the top layer.
    Appear for the duration of the slide, no transitions, and pause until the user clicks.
    I noticed if you type fast (as the learner) it kinda messes everything up. Add a distraction so you learner slows down on their typing speed.
    Also make sure you have the update installed. There were some bugs fixed in the TEB area.
    Good luck. email if you have any more questions.

  • How can I get the escape key to work again?

    I've used "esc" to get out of VI's insert mode for 40 years. I am not going to relearn that keystroke as "ctl-esc", period. Even if I were to do that, then I'd be typing ctl-esc on other platforms where it would not work because I have to type "esc" alone. If there is a way to fix in in System Preferences->keyboard, I cannot find it. If there is not, then it is completely 100% brain-dead wrong. I hope that's not the case.  So there is definitely a bug:
    The key-up event on the escape key does not cause the escape key code to be delivered to the active window when no other key is pressed, or
    The UI is sufficiently obtuse that the cause of the suppression cannot readily be found.
    I do hope it is merely the latter because I am compelled to use Outlook and Outlook does not work properly under OS/X 10.6.  (Our Exchange Server is rigged to only allow Outlook clients to send email outside of the company.)
    Thank you.

    The answer is:  The bug is in the UI.  Speech recognition was enabled, by default it uses the bare escape key as a "mic on" indicator, and it does not leave any trace in the keybord configuration.  So that is the bug.  It needs to leave a trace there, a la: "X Listen-for-voice-command  ^" under Mission Control.

  • Why do I have to use the tab key even more to tab between page elements.

    Firefox versions prior to ver 4 I used the tab key to tab between page elements (form elements, buttons, etc). I upgraded to ver 4 and now when I tab from form element to form element I first see a gray line outlining the element area and then another press of the tab the element becomes active for me to use. I now have to use double the tab keys to move between form elements.

    Hello new_mac_user, see if the next works
    # In the [[Location bar autocomplete|Location bar]], type '''about:config''' and press '''Enter'''. The about:config "''This might void your warranty!''" warning page may appear.
    # Click '''I'll be careful, I promise!''', to continue to the about:config page.
    # in search field type (or copy/paste from here) '''accessibility.tabfocus'''
    # double-click on it and change the value to '''4''' (probably you have 1 the default on mac)
    # click ok, exit firefox and restart it.
    with the above you give focus to links (and linked images) only when you press the tab key.
    see for more info : http://kb.mozillazine.org/Accessibility.tabfocus
    https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/Preference_reference/accessibility.tabfocus
    thank you

  • Apple wireless keyboard won't let me delete without using the fn key.

    My apple wireless keyboard won't let me delete in indesign without using the fn key. Is there a key command that I accidentally hit that causes that or something? I've never had this happen before. It isn't happening in any other program, just indesign cs4. Has anyone had this happen and how do I fix it?

    I figured it out. My keyboard shortcut set in indesign was corrupt. I went back to the default set and created a new set and the delete key started working again.

  • I can't scroll using the arrow keys!!

    I have been having a problem lately where I cannot scroll within applications using the up and down arrow keys. on my macbook, using the arrow keys is something i liked to do to scroll in a page instead of using the trackpad, and now it doesn't work... I've noticed it in every web browser installed on the laptop (Safari, Firefox, Camino) and also doesn't work in itunes (making it annoying to easily scroll to another song in the library!) or AIM or other programs... anybody know how I can fix this? thanks.

    Hello and Welcome to Apple Discussions!
    Full keyboard access is useful for people who have difficulty using a mouse. Safari supports standard full keyboard access shortcuts for buttons and menus. If you choose, you can also use the keyboard to highlight links in webpages.
    To turn on full keyboard access:
    Choose Apple menu > System Preferences and click Keyboard & Mouse.
    Click Keyboard Shortcuts.
    Select the checkbox to turn on full keyboard access.
    To highlight links in webpages using the Tab key:
    Choose Safari > Preferences and click Advanced.
    Select the option to highlight each item on the web page using the Tab key.
    With full keyboard access turned on, Safari uses the standard shortcut keys to access menus and windows, plus the additional shortcuts shown in the table.
    Hope this helps!!
    Carolyn

  • IPhoto won't let me open it using the option key

    When I try to open iphoto with the option key held down I get tne error message "the library is a Time Machine copy and cannot use". The only option I have is to Quit which gives me a viscous circle. How can I change to another library without opening using the option key.

    Thanks for the reply.
    I am not trying to use a library from a Time Machine backup. I have made a library from Time Machine by restoring it and that is the one I want to use.
    It had worked just two weeks ago, but now I am getting the error message with only the "QUIT" option and the revolving circle indicating the program is trying but not suceeding.
    I believe iPhoto is pointing to the pictures in my user's files - MacSSD/Users/JBL/pictures. I deleted a small iPhoto Library (7.4mb) that had been given a 3/14/14 designation and now there isn't an iphoto library in pictures. I'm not sure how that file got created, but iPhoto started last using the restored library that resides on an external hard drive.
    How can I determine where iPhoto is pointing to find the library without opening iPhoto which I can't do because of the circular QUIT option?
    Any further help will be most appreciated.

Maybe you are looking for