0 Replies Latest reply on Jun 22, 2010 3:10 AM by Luca Crescenzi

    Keyboard on screen

    Luca Crescenzi

      Hello  everybody,
      I’m trying to create a monitor keyboard (for touchscreen  devices) but currently I have inserted just 4 keys in order to find the  right method. I thought I could use dispatchEvent to simulate the  pressure exerted on a key of the keyboard every time I press a button  component on the screen. The simulation seems to work (as the listener I  have set on KEYDOWN events correctly detects the pressure on the key)  but the problem is I can’t write down anything...

      Thanks  in advance to anyone who will be willing to help me! Here is the code



      Of course all this should work on an AIR application created  with FLASH BUILDER (sdk 3.5)

       

       

       

      Luca

       

      <?xml version="1.0" encoding="utf-8"?>
      
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="300" height="200" initialize="createListener(event);">
      
          <mx:Button x="10"  y="100" label="A" id="key_A" click="this.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false,65,65));"/>
      
          <mx:Button x="58"  y="100" label="B" id="key_B" click="this.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false,66,66));"/>
      
          <mx:Button x="106" y="100" label="C" id="key_C" click="this.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false,67,67));"/>
      
          <mx:Button x="154" y="100" label="D" id="key_D" click="this.dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false,68,68));"/>
      
          <mx:TextInput x="10" y="10" width="281" id="TextBox1"/>
      
          <mx:TextInput x="10" y="33" width="281" id="TextBox2"/>
      
          <mx:TextInput x="10" y="56" width="281" id="TextBox3"/>
      
          <mx:Script>
      
              <![CDATA[
      
                  import flash.events.*;
      
                  import mx.controls.Alert;
      
                  private function createListener(e:Event):void {
      
                      this.addEventListener(KeyboardEvent.KEY_DOWN, myClickHandler);
      
                  }
      
                  private function myClickHandler(e:KeyboardEvent):void {
      
                      if (e.keyCode == 65) {
      
                          Alert.show("E' stato premuto il tasto A  ");
      
                      }
      
                      if (e.keyCode == 66) {
      
                          Alert.show("E' stato premuto il tasto B  ");
      
                      }
      
                      if (e.keyCode == 67) { 
      
                          Alert.show("E' stato premuto il tasto C  ");
      
                      }
      
                      if (e.keyCode == 68) {
      
                          Alert.show("E' stato premuto il tasto D  ");
      
                      }
      
                  }
      
              ]]>
      
          </mx:Script>    
      
      </mx:WindowedApplication>