fletchergames
|
 |
«
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?
|
|
|
|
|
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?
|
|
|
|
fletchergames
|
 |
«
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!
|
|
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...
|
|
|
|
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
|
|
|
|
Coinerson
Junior Member  
Introducing the world's cutest zombie, Timmy
|
 |
«
Reply #5 - Posted
2007-03-13 22:32:48 » |
|
consume keys you dont use.
|
|
|
|
|
ryanm
« League of Dukes » 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]
|
|
|
|
|
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?
|
|
|
|
|
fletchergames
|
 |
«
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.
|
|
|
|
|
fletchergames
|
 |
«
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!
|
|
Kova
|
 |
«
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...
|
|
|
|
|
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?
|
|
|
|
fletchergames
|
 |
«
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.*;
public class GameKeyListener implements KeyListener {
public GameKeyListener(final boolean shouldDisableMnemonics) { this.shouldDisableMnemonics = shouldDisableMnemonics; for(int iKeyState = 0; iKeyState < numKeys; iKeyState++) aKeyState[iKeyState] = InputSourceState.UP; }
public void clearInput() { keyTyped = KeyEvent.CHAR_UNDEFINED; for(int i = 0; i < numKeys; i++) wasKeyPressed(i); }
public char getLastKeyTyped() { char lastKeyTyped = keyTyped; keyTyped = KeyEvent.CHAR_UNDEFINED; return lastKeyTyped; }
public void listenTo(final Component component) {component.addKeyListener(this);}
public void listenToContainerAndSubcomponents(final Container container) { if(container == null) return;
container.addKeyListener(this);
for(SubcomponentIterator iSubcomponent = new SubcomponentIterator(container); iSubcomponent.hasNext(); ) { Component subcomponent = iSubcomponent.next(); subcomponent.addKeyListener(this); if(subcomponent instanceof Container) listenToContainerAndSubcomponents((Container)subcomponent); } }
public boolean wasAnyKeyPressed() { return GameEventUtil.wasAnyInputSourcePressed(aKeyState); }
public boolean wasAnyKeyReleased() { return GameEventUtil.wasAnyInputSourceReleased(aKeyState); }
public boolean wasKeyPressed(final int keyCode) { return GameEventUtil.wasInputSourcePressed(aKeyState, keyCode); }
public boolean wasKeyReleased(final int keyCode) { return GameEventUtil.wasInputSourceReleased(aKeyState, keyCode); }
public void keyPressed(final KeyEvent event) { int keyCode = event.getKeyCode(); if(keyCode < numKeys) aKeyState[keyCode] = InputSourceState.DOWN;
if(shouldDisableMnemonics) event.consume(); }
public void keyReleased(final KeyEvent event) { int keyCode = event.getKeyCode(); if(keyCode < numKeys) aKeyState[keyCode] = InputSourceState.RELEASED;
if(shouldDisableMnemonics) event.consume(); }
public void keyTyped(final KeyEvent event) { keyTyped = event.getKeyChar(); if(shouldDisableMnemonics) event.consume(); } private static final int numKeys = 600;
private InputSourceState[] aKeyState = new InputSourceState[numKeys]; private char keyTyped; private final boolean shouldDisableMnemonics; } |
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.
|
|
|
|
|
cylab
|
 |
«
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!
|
|
|
fletchergames
|
 |
«
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.
|
|
|
|
|
Kova
|
 |
«
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?
|
|
|
|
|
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...
|
|
|
|
fletchergames
|
 |
«
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.
|
|
|
|
|
|