3 Replies Latest reply on Mar 3, 2008 1:28 PM by Joe ... Ward

    Focus

    Kevin_Ashworth
      Is it possible to capture keystrokes (KeyboardEvent) in a new AIR window without clicking in it first? Or an existing window that you come back to via Alt+Tab?

      I've been trying to use setFocus on this and that, to no avail. I wonder if it's at all possible....
        • 1. Re: Focus
          KPE3000 Level 1
          Generally windows do not recieve keystrokes from the OS when it's not active/focused.

          I've seen a transparent AIR demo, where you can draw on the desktop. I don't know how it works, but a transparent window on top might be able to receive all keystrokes, though I would doubt it.
          • 2. Re: Focus
            Kevin_Ashworth Level 1
            Hmm. I wonder if via AIREvent.APPLICATION_ACTIVATE I could set something to start to process keystrokes without clicking. Nothing so far.

            Other applications start to process keystrokes immediately -- like the browser I'm using to type this. Will continue to search for a way within AIR.
            • 3. Focus
              Joe ... Ward Level 4
              Try this:
              <?xml version="1.0" encoding="utf-8"?>
              <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()">
              <mx:Script>
              <![CDATA[
              private function init():void{
              trace("starting");
              it.addEventListener(KeyboardEvent.KEY_DOWN, onKey);
              focusManager.setFocus(it);
              }

              private function onKey(event:KeyboardEvent):void{
              trace("Key " + event.keyCode);
              }
              ]]>
              </mx:Script>
              <mx:TextArea id="it" x="10" y="10" width="602" height="544"/>
              </mx:WindowedApplication>