Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (428)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Escape Key Minimizing Java Program  (Read 2806 times)
0 Members and 1 Guest are viewing this topic.
Offline fletchergames

Senior Member





« Posted 2007-03-13 01:57:12 »

I'm working on a full-screen Java 1.6 program on Windows XP service pack 2.  Whenever I press escape, sometimes the game minimizes.  At first, I thought this was some feature of Eclipse, but it happens even when I'm not running the game from Eclipse.

This is a real problem because escape is supposed to go to the main menu.

Anyone know how to stop this behavior?
Offline SimonH
« Reply #1 - Posted 2007-03-13 02:11:53 »

I'm wondering why only sometimes? ESC shouldn't minimise windows anyway... Anything else running on the machine?

People make games and games make people
Offline fletchergames

Senior Member





« Reply #2 - Posted 2007-03-13 02:57:44 »

Generally, I'm running Eclipse and a text editor called Textpad.  There's been times when I've had other things open as well, but I'm sure there's been times when it occurred and I had nothing running except Norton Antivirus and Spyware Doctor.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SimonH
« Reply #3 - Posted 2007-03-13 03:28:40 »

I'm sure there's been times when it occurred
Intermittent ones are the worst! I can't think of any circumstances where ESC would do that on XP - I could understand if it was losing focus, but minimising? Harsh! You should check what process takes input focus after the window's minimised...

People make games and games make people
Offline CommanderKeith
« Reply #4 - Posted 2007-03-13 08:27:06 »

This hasn't happened with me but the only way I can think of it happening is if the ESC key is bound to an action in the AWT.  You can easily set an empty binding by doing some method like component.setActionMap(new HashMap()).

Keith

Offline Coinerson

Junior Member




Introducing the world's cutest zombie, Timmy


« Reply #5 - Posted 2007-03-13 22:32:48 »

consume keys you dont use.
Offline ryanm

Senior Member


Projects: 1


Used to be bleb


« Reply #6 - Posted 2007-03-13 23:47:52 »

consume keys you dont use.

Note that this advice should only be taken if your keyboard is made of ham.
[/unhelpful]
Offline Coinerson

Junior Member




Introducing the world's cutest zombie, Timmy


« Reply #7 - Posted 2007-03-14 00:29:56 »

Note that this advice should only be taken if your keyboard is made of ham.
[/unhelpful]

A) My keyboard is made of the finest of swiss cheeses.
B) What?
C) I don't use those acutally, just popped into my brain when reading the question.
D) Perhaps his keyboard is made out of ham?
Offline fletchergames

Senior Member





« Reply #8 - Posted 2007-03-14 04:24:03 »

This hasn't happened with me but the only way I can think of it happening is if the ESC key is bound to an action in the AWT.  You can easily set an empty binding by doing some method like component.setActionMap(new HashMap()).

Keith
I did this and now it works, though I have no idea why Escape would be mapped to minimization by default.  In Windows (at least on my PC), Ctrl-Escape opens/closes the start menu and Alt-Escape cycles through the programs that are open.  It seems unlikely that I was using either of those key combinations by accident because neither Ctrl nor Alt is used by my game.

In any case, the problem hasn't happened since.

I was already consuming all keyboard events, but that apparently doesn't affect the ActionMap.
Offline fletchergames

Senior Member





« Reply #9 - Posted 2007-03-24 16:09:53 »

The "fix" is still in place, but it isn't working anymore.  The problem just didn't happen for a while.

I don't know why the Escape key is minimizing the program, and I don't know how to fix it.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Kova

Senior Member





« Reply #10 - Posted 2007-03-24 22:51:20 »

when I got into that kind of trouble when I couldn't fix the thing... I just started building game over and try to see after what addon bug arises. Of course this takes lots of time...
Offline SimonH
« Reply #11 - Posted 2007-03-25 04:03:13 »

There must be an answer to this; Escape key presses don't normally minimise windows...

Few thoughts...
Can you post your key-capture code? I always use keyPressed() &c. (but that's applets) - How are you handling keys?
Are you running more than one focus-capturing component? Is the minimising coming from somewhere else?
What takes focus when the window minimises? Is some other process taking focus off you?

People make games and games make people
Offline fletchergames

Senior Member





« Reply #12 - Posted 2007-03-27 04:43:19 »

Here's my keylistening code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
package cg.gui.event;
import cg.gui.SubcomponentIterator;

import java.awt.*;
import java.awt.event.*;

/**This class handles keyboard input for games.
 * @author Steven Fletcher
 * @since 2005/02/08
 * @version 2007/02/28*/

public class GameKeyListener implements KeyListener {
/**Constructor
 * @param shouldDisableMnemonics whether to disable keyboard mnemonics*/

public GameKeyListener(final boolean shouldDisableMnemonics) {
   //set up the keyboard
  this.shouldDisableMnemonics = shouldDisableMnemonics;
   for(int iKeyState = 0; iKeyState < numKeys; iKeyState++)
      aKeyState[iKeyState] = InputSourceState.UP;
} //end constructor

/**Forget all the current keyboard input.*/
public void clearInput() {
   keyTyped = KeyEvent.CHAR_UNDEFINED;
   for(int i = 0; i < numKeys; i++)
      wasKeyPressed(i);
} //end clearInput

/**Get the Ascii value of the last key "typed" (according to KeyListener).
 * @return the last character typed*/

public char getLastKeyTyped() {
   char lastKeyTyped = keyTyped;
   keyTyped = KeyEvent.CHAR_UNDEFINED;
   return lastKeyTyped;
} //end getLastKeyTyped

/**Listen to a given Component.
 * @param component the Component to listen to*/

public void listenTo(final Component component) {component.addKeyListener(this);}

/**Adds the specified KeyListener to all Components included in the specified Container.
 * Note that the KeyListener won't be added to Components added to the Container later
 * @param container the Container to listen to*/

public void listenToContainerAndSubcomponents(final Container container) {
   //verify that the Container isn't null
  if(container == null)
      return;

   container.addKeyListener(this);

   //for each subcomponent of this ViewPane, add the global KeyListener
  for(SubcomponentIterator iSubcomponent = new SubcomponentIterator(container);
      iSubcomponent.hasNext(); )
   {
      Component subcomponent = iSubcomponent.next();
      subcomponent.addKeyListener(this);
      if(subcomponent instanceof Container)
         listenToContainerAndSubcomponents((Container)subcomponent);
   } //end for each subcomponent of the Component
} //end listenToContainerAndSubcomponents

/**Determines whether ANY key was pressed since the last time we checked.  This
 * method doesn't clear the states of any of the keys.
 * @return whether ANY key was pressed since the last time we checked*/

public boolean wasAnyKeyPressed() {
   return GameEventUtil.wasAnyInputSourcePressed(aKeyState);
} //end wasAnyKeyPressed

/**Determines whether ANY key was released since the last time we checked.  This
 * method doesn't clear the states of any of the keys.
 * @return whether ANY key was released since the last time we checked*/

public boolean wasAnyKeyReleased() {
   return GameEventUtil.wasAnyInputSourceReleased(aKeyState);
} //end wasAnyKeyReleased

/**Determines whether the key, keyCode, was pressed since the last time we checked.
 * If it was pressed, it's state is cleared to UP.
 * @param keyCode code of the key to check (see class KeyEvent in the Java API)
 * @return whether the key, keyCode, was pressed since the last time we checked*/

public boolean wasKeyPressed(final int keyCode) {
   return GameEventUtil.wasInputSourcePressed(aKeyState, keyCode);
} //end wasKeyPressed

/**Determines whether the key, keyCode, was released since the last time we checked.
 * If it was released, it's state is cleared to UP
 * @param keyCode code of the key to check (see class KeyEvent in the Java API)
 * @return whether the key, keyCode, was released since the last time we checked*/

public boolean wasKeyReleased(final int keyCode) {
   return GameEventUtil.wasInputSourceReleased(aKeyState, keyCode);
} //end wasKeyReleased

//LISTENERS//////////////////////////////////////////////////////////////////////////////
//KeyListener methods
/**Implements the KeyListener interface.  Do not call this method directly.
 * @param event the KeyEvent that occurred*/

public void keyPressed(final KeyEvent event) {
   int keyCode = event.getKeyCode();
   if(keyCode < numKeys)
        aKeyState[keyCode] = InputSourceState.DOWN;

   if(shouldDisableMnemonics)
      event.consume();
} //end keyPressed

/**Implements the KeyListener interface.  Do not call this method directly.
 * @param event the KeyEvent that occurred*/

public void keyReleased(final KeyEvent event) {
   int keyCode = event.getKeyCode();
   if(keyCode < numKeys)
      aKeyState[keyCode] = InputSourceState.RELEASED;

   if(shouldDisableMnemonics)
      event.consume();
} //end keyReleased

/**Implements the KeyListener interface.  Do not call this method directly.
 * @param event the KeyEvent that occurred*/

public void keyTyped(final KeyEvent event) {
   keyTyped = event.getKeyChar();
   if(shouldDisableMnemonics)
      event.consume();
} //end keyTyped

//CONSTANTS//////////////////////////////////////////////////////////////////////////////
//keyboard
private static final int numKeys = 600;

//VARIABLES//////////////////////////////////////////////////////////////////////////////
private InputSourceState[] aKeyState = new InputSourceState[numKeys];
private char keyTyped;
private final boolean shouldDisableMnemonics;
} //end class GameKeyListener


I'm using this class with mnemonics disabled.

I added this listener to every Component added to the game so that focus wouldn't be an issue.  It's a full-screen exclusive mode game.

The problem has only occurred once since I cleared the action map.  The focus isn't going to another process so far as I can tell - the game just minimizes.  Normally, when the game minimizes it stops playing, but when it minimizes from pressing escape the game just keeps going.  I guess this means the game isn't receiving the event saying that it's been minimized.
Offline cylab

JGO Knight


Medals: 34



« Reply #13 - Posted 2007-03-27 07:57:51 »

Do you have any code to minimize the window in your project? If yes, then you can place a breakpoint there, debug the application and once the breakpoint is reached, check the call stack to find the wrong call. If you don't have such code, then most likely some utility you have installed (maybe norton) grabs the key on a global level and your code is not the problem.

Mathias - I Know What [you] Did Last Summer!
Offline fletchergames

Senior Member





« Reply #14 - Posted 2007-03-27 16:13:04 »

There's no code that minimizes the window.  So I guess it must be something else.  I have several utility programs running most of the time.
Offline Kova

Senior Member





« Reply #15 - Posted 2007-03-27 17:31:38 »

does the problem appear on other computers? do other java apps suffer from same problem on your computer?
Offline SimonH
« Reply #16 - Posted 2007-03-27 17:47:46 »

Key code's clean, intermittent occurrance, no minimising code within game; sounds like an external utility problem to me too.
You could chuck a system.out.println(keycode) at the top of keyPressed() to check if you actually get the esc keypress when the bug happens...

People make games and games make people
Offline fletchergames

Senior Member





« Reply #17 - Posted 2007-03-28 04:34:38 »

I've never encountered this problem on a different computer and never heard of it happening to anyone ask.  I did ask someone who played the game about by email, but he never replied.

I don't recall ever having this happen on any other program.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (79 views)
2014-04-15 18:08:23

BurntPizza (71 views)
2014-04-15 03:46:01

UprightPath (82 views)
2014-04-14 17:39:50

UprightPath (66 views)
2014-04-14 17:35:47

Porlus (82 views)
2014-04-14 15:48:38

tom_mai78101 (106 views)
2014-04-10 04:04:31

BurntPizza (166 views)
2014-04-08 23:06:04

tom_mai78101 (262 views)
2014-04-05 13:34:39

trollwarrior1 (212 views)
2014-04-04 12:06:45

CJLetsGame (221 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!