I need help to catch and suppress ESC button on F3

Former Member
Former Member
In my App Golf_SC (Scorecard for Golf) I would like to prevent the ESC/Back button to cause the App to terminate (nominally, with saved properties and cleaned up environment etc.) and rather close and terminate the app by a corresponding menu item only.

I know that this is a bit against the conventions that F3 users are used to and might expect, but there is a good reason, that would apply also for further cases (see below):

When I have the app open and running during a golf round, the process of hitting the ball with a glove sometimes presses the back button without intention. I then find myself with a terminated activity recording, and have to restart the app. Therefore I'd like to intercept the ESC key (is that possible by returning "true"?) and then initiate app termination by responding to a menu item.

Could anybody from the more experienced people here give a hint?
  • I do a similar thing on the vivoactive, where I catch the "onBack" event and return true or false based on what the app is doing at the time. (true if I handled it, false if the default handler should do it).

    As far as the exit from a menu, I've tried using Sys.exit(), but it doesn't result in a "clean" exit, and you get an extra screen the user has to clear.
  • Former Member
    Former Member over 10 years ago
    OK, I think I nailed it.

    If there is currently an active recording AND the user has not requested to quit by menu, the key event is ignored by returning true.

    If there is no active recording, the app just quits, as it normally should.

    If there is an active recording, and the user selects "Exit" from the menu, the app closes the recording and quits gracefully.

    That should avoid unintended "quits" during the round just because the glove or hand back hit the esc/back button.