4 Replies Latest reply on Jan 25, 2011 1:56 AM by Garry Taylor

    Capture Ctrl-A?

    Garry Taylor

      Hi all,

      Simple question, I need to prevent a "select all" event. When a user presses Ctrl-A in my app, it selects all the text, and looks very ugly. I've been able to prevent selection using the mouse, but Ctrl-A still works. I've tried this:


      nativeWindow.addEventListener(air.Event.SELECT_ALL, function () {alert("select all");});


      But it does not do anything, how can I get hold of this event and stop it from selecting everything?





        • 1. Re: Capture Ctrl-A?
          commadelimited Level 2



          Probably the easiest thing to do would be to listen for the keydown event

          (ctrl), and return a function, then inside that listen the keyup event. If

          the ctrl key is still down when the A key is pressed, then return false.


          I will say though that this might irritate your users. I know that if I was

          expecting to be able to select all so that I could copy something, and was

          prevented from doing so, I'd just close the app and never come back. If

          you're simply trying to prevent users from extracting your content then

          they'll get it no matter what you do to stop them.




          1 person found this helpful
          • 2. Re: Capture Ctrl-A?
            Garry Taylor Level 1

            I agree entirely this could be irritating to the users, the problem is that Ctrl-A is selecting everything in the window, and I'm trying to make a proper "application", not a web page. It selects my labels, checkboxes, and all other window furniture and looks very ugly.


            If I can crack the selection, then I can put in some ifs/buts if the user is legitimately trying to select all inside a text field or something.





            • 3. Re: Capture Ctrl-A?
              Saumitra Bhave Level 3



                   if(e.ctrlKey && e.keyCode == Keyboard.A){




                        //e.preventDefault(); use this to cancel out this key press. And does not do what Ctra + A by default does





              1 person found this helpful
              • 4. Re: Capture Ctrl-A?
                Garry Taylor Level 1

                Is this Javascript? If so, I can't seem to get it work, but your solution gave me a clue and now I can stop Ctrl-A from doing anything.


                I have no problem with user getting information out of the app, but I don't want them to be able to select UI furniture as it looks ugly, and not like a desktop application they would be used to.