5 Replies Latest reply on Feb 11, 2009 4:02 PM by Loveanie

    Capturing F5

    IwannaFlashU Level 1
      I thought I posted this question a long time ago, but did a search and nothing came up, so here goes:

      We create custom eLearning and are having a problem with a client of ours where pressing F5 causes a loss of communication with their LMS and our course. So we want to trap the F5 key.

      Now, we already have javascript that traps it, but once the flash piece has the focus, that code no longer works. The code we have in Flash to trap the F5 key apparently works in firefox but not in IE. I have searched all over the web and it seems that the question is asked over and over again and no one has the solution. I even signed up at that expert's site, that claimed to have a solution and they didn't. So you guys are my last shot.

      Anyone here know how to capture the F5 key from within Flash, so a web page cannot be refreshed? Thanks!
        • 1. Re: Capturing F5
          Loveanie Level 1
          If you're working with AS 3.0, you can use that:

          stage.addEventListener(KeyboardEvent.KEY_DOWN, capture);

          function capture(evt:KeyboardEvent):void {
          if (evt.keyCode == Keyboard.F5) {
          // do nothing

          P.S. If you're testing in Flash, you'll need to deactivate the keyboard shortcuts (Ctrl-Enter, then Control --> Disable Keyboard Shortcuts).

          It works only if the Flash Player has the focus... which seems to be what you want...
          • 2. Re: Capturing F5
            Loveanie Level 1
            Sorry, I work more with AS 3.0 now... but I just realized it's a AS 1.0 - 2.0 forum...

            So, in AS 2.0, you would do it like that:

            var f5Listener:Object = new Object();
            f5Listener.onKeyDown = function() {
            if (Key.getCode() == 116) {
            // do nothing
            • 3. Re: Capturing F5
              Ned Murphy Adobe Community Professional & MVP
              I have my doubts that this will supress the action taken by the f5 key, it will only do nothing in reaction to it being pressed. For example, if I press any letter/number key while filling in a textfield, I can recognize that the key was pressed, but in order to make that pressing ineffective I have to actively remove the last character entered. Doing nothing would simply offer a flag to something that the key was pressed, but the character will still appear in the textfield.
              • 4. Re: Capturing F5
                IwannaFlashU Level 1
                Yes, we already tried that type of code.

                Except instead of "do nothing", we call the same javascript function that is called when flash doesnt have the focus and the f5 key is pressed (to trap it in that instance). This worked in firefox but not in ie, but of course, our client is "ie only" so that does us no good.
                • 5. Re: Capturing F5
                  Loveanie Level 1
                  True, I only tested it in Firefox... I suppose IE don't let you override shortcut keys...