Adobe AIR: Preventing Users from Closing the App

One of the really cool additions to Adobe AIR 1.5.2 was the ability to invoke preventDefault() upon a FullScreenEvent when using StageDisplayState.FULL_SCREEN_INTERACTIVE. I always had a workaround for Windows but my method would always crash the app when run on a Mac. The ability to go full screen and lock that down is essential to kiosk-type applications. This does not prevent a user from closing out the app in some other way, however.

While working on an AIR-based kiosk project this week, I was given the request to prevent COMMAND+Q from closing the application on a Mac. They really wanted this thing locked down to the point where the only way to get out of the app would be to enter some random key combination. Took a little bit of digging around to figure out how to both prevent the default closing action but still allow the app to close in the event that the correct key commands were entered. I share this here as I can see others having this same need.



	
		
	
	
		
	

UPDATE: If you have a stateful application, you may want to consider the following information, as it may be disruptive in handling these events properly: http://beingwicked.com/development/flex-initialize-and-the-hassles-of-changing-state/

11 thoughts on “Adobe AIR: Preventing Users from Closing the App”

  1. Hey, I’m also building a kiosk app out and am having trouble with your example here…

    It works fine as long as the user has their focus on the stage, but as soon as they click on another component(say, a button) then the ESC key will bring the application back to windowed mode again.

    Any ideas?

  2. I don’t see why they wouldn’t, I’m not capturing events in any other way. It actually seems to be related to a state change in the application – I have a button that changes the state of the application to a new one, and when it’s clicked, the user can then press ESC if they want and exit full-screen mode. However, if they click the button to change the state of the application, and then click somewhere else on the stage, they are then unable to hit ESC to exit full-screen.

    I’m wondering if manually setting the focus on state-change will fix this.

  3. Does this code work to lock down the app on a PC running Windows? Have you built a kiosk AIR app that is intended to be cross-platform between mac and PC?

  4. Using AIR 1.5.3 and this works great to prevent the ESC key from bringing the app out of full screen, but Alt+F4 and the windows key are still giving me trouble. :/

    Building in the Flash IDE, though, so there may be a limitation there. I’m sure the mx.events.CloseEvent is rather important, but alas, Flash doesn’t seem to see it. :)

    1. Yeah- there is always some way around it. Not sure if it can be totally locked down. For most kiosk projects I’ve done, they lock the keyboard away and only let the user have touch access to the screen.

      With the Flash IDE, you can check out:
      flash.events.Event.CLOSING

  5. Great post. I was wondering if you know how to prevent the windows start menu from popping up when the user presses any of the windows/start keys

  6. Hi!
    I think calling a KEY_DOWN event handler killApp is not a good idea. Event handlers should always be named after the event they listen to.
    So in this case:

    stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown);
    ….
    private function handleKeyDown(e:KeyboardEvent):void {

Leave a Comment

Your email address will not be published. Required fields are marked *