Disabling Escape to exit fullscreen

3,044 views
Skip to first unread message

Dustin Auxier

unread,
Feb 22, 2015, 7:54:12 PM2/22/15
to haxef...@googlegroups.com
Hello, I was working on adding fullscreen abilities to my game and noticed that the Escape Key while in fullscreen drops back to windowed, but that's not from any code I've written. I'd like to use the escape key for in-game menus, so is there a way to disable this? Had a look around but couldn't find anything.

Nazywam

unread,
Feb 23, 2015, 1:58:10 AM2/23/15
to haxef...@googlegroups.com
Hey,
Have a look at this thread https://github.com/openfl/openfl/issues/36

I think overwriting escape is done in the same way

Dustin Auxier

unread,
Feb 23, 2015, 5:38:37 PM2/23/15
to haxef...@googlegroups.com
That worked, thank you!

Ats

unread,
Jul 31, 2015, 10:54:48 AM7/31/15
to haxef...@googlegroups.com, dust...@gmail.com
Hi Dustin,
can you provide the bit of code you wrote to make it work?
I've just tried:

import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

...

FlxG.stage.addEventListener (KeyboardEvent.KEY_DOWN, stage_onKeyDown);

...

private function stage_onKeyDown (event:KeyboardEvent):Void
{
 
if (event.keyCode == Keyboard.ESCAPE)  event.stopPropagation();
}


But the escape key keeps exiting the fullscreen mode... Am I missing something?
Thanks for your help.

Dustin Auxier

unread,
Jul 31, 2015, 12:04:59 PM7/31/15
to HaxeFlixel, dust...@gmail.com, ati...@gmail.com
That's exactly what I have, which works for me. :\

FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN, stageKeyDown);

...

private function stageKeyDown(e:KeyboardEvent):Void
{
if (e.keyCode == Keyboard.ESCAPE)
{
e.stopPropagation();
}
}

Ats

unread,
Jul 31, 2015, 12:31:26 PM7/31/15
to HaxeFlixel, dust...@gmail.com, ati...@gmail.com
Damn... I just checked my Project.xml and Main.hx but there is nothing that could interfer and my eventListener is working correctly...
You are going fullscreen using FlxG.fullscreen = !FlxG.fullscreen; right?
Maybe that comes from HaxeFlixel version? I'm using the lastest git version. And you?
Thanks for your time.

Dustin Auxier

unread,
Jul 31, 2015, 3:20:43 PM7/31/15
to HaxeFlixel, dust...@gmail.com, ati...@gmail.com
Yeah I'm toggling fullscreen the same way. I haven't updated libraries in a while so that may be it, I have openFL 3.1.0, lime 2.4.3, flixel 3.3.8.

Ats

unread,
Aug 3, 2015, 7:27:30 AM8/3/15
to haxef...@googlegroups.com, dust...@gmail.com, ati...@gmail.com
So I've just tried a lot of things without success...

When I trace event.toString() I get:
[KeyboardEvent type="keyDown" bubbles=true cancelable=false eventPhase=2 charCode=27 keyCode=27 keyLocation=0 ctrlKey=false altKey=false shiftKey=false]
Is there a way to force cancelable = true ? This can only be set when making a event.new().

-----
Edit: I've find a way to force cancelable to true, but that didn't changed a thing..

private var testEvent:KeyboardEvent;
...
testEvent
= new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, true, 27, 27);
FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);

...
private function stage_onKeyDown (event:KeyboardEvent):Void
{
 
if (event.keyCode == Keyboard.ESCAPE)

 
{
 testEvent
.stopPropagation();
 
FlxG.log.add(testEvent.toString());
 
}
}
-----

Also on this blog (http://kpulv.com/129/Disable_ESC_in_Fullscreen_on_Adobe_AIR/) it is said that using stopPropagation() is impossible in a normal swf build and works only in Adobe AIR. So I tried to compile to neko but the escape key is not escaping the fullscreen at all in this target.

I've also tried to import
import openfl.events.KeyboardEvent;
import openfl.ui.Keyboard;
instead of
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;

Here's my library versions.
openFL[3.2.2]
lime[2.5.2]
flixel git
Is there a way to compare with older versions on github?

Dustin Auxier

unread,
Aug 3, 2015, 11:48:29 AM8/3/15
to haxef...@googlegroups.com, dust...@gmail.com, ati...@gmail.com
Ohh I'm using the desktop target here. I don't have a fullscreen option at all for my swf version of the game, so here's where our difference is.

Ats

unread,
Aug 3, 2015, 1:32:28 PM8/3/15
to haxef...@googlegroups.com, dust...@gmail.com, ati...@gmail.com
You are totally right. After a bunch of readings, it appears that it is a design choice from Adobe to exit fullscreen while pressing escape key on the flash player exe.
Still, I've managed to find an (ugly) method to force staying in full screen :)

First, you got to have a savefile ready for accessing a fullscreen bool from every states:

package common;

import flixel.util.FlxSave;

class SaveFile
{
 
private static var _save:FlxSave;
 
private static var _loaded:Bool = false;
 
private static var _fullscreen:Bool = false;
 
 
public inline function new()
 
{
  load
();
 
}

 
public static function load():Void
 
{
  _save
= new FlxSave();
  _loaded
= _save.bind("savefile");
 
 
if (_loaded) {
   
if (_save.data.fullscreen == null) _save.data.fullscreen = _fullscreen;
 
} else {
   _save
.data.fullscreen = _fullscreen;
 
}
 
}

 
public var fullscreen(get, set):Bool;
 
function get_fullscreen() { if (_loaded) return _save.data.fullscreen; else return _fullscreen; }
 
function set_fullscreen(bool:Bool) { if (_loaded) return _save.data.fullscreen = bool; else return _fullscreen = bool; }
}

Then you just ask on your state update if the FlxG.fullscreen is equal to your savefile boolean:

import common.SaveFile;
 
...
private var saveFile:SaveFile = new SaveFile();
...
override public function update(elapsed:Float):Void
{
 
super.update(elapsed);
 
 
if (FlxG.keys.anyJustPressed([122])) // press F11 to go/exit fullscreen
 
{
    saveFile
.fullscreen = !saveFile.fullscreen;
   
FlxG.fullscreen = saveFile.fullscreen;
 
}
 
if (saveFile.fullscreen && !FlxG.fullscreen) FlxG.fullscreen = saveFile.fullscreen;
}

That's it. When you press escape to exit your menu or change state, the flash player will exit fullscreen and then go back to fullscreen by itself. But it's very ugly.
Now that I've messed with flash player, it's time to move on to desktop target :)

Thanks Dustin for your time.
Reply all
Reply to author
Forward
0 new messages