Keyboard events

Hello

I'm doing some tests trying to move an image around the screen. For that, I add listeners as follows:

addEventListener(KeyboardEvent.KEY_DOWN, key_pressed);
....
private function key_pressed(e:KeyboardEvent):void {
switch (e.keyCode) {
....

But the events key_pressed function is never called.

No idea what I'm doing wrong here?

Thank you

Try stage.addEventListener etc.

I don't know where you add currently only eventListener to. If you don't want it to apply to the whole scene, specify the object you want to join the eventListener to.

To make things work.

Tags: BlackBerry Developers

Similar Questions

  • Capturing keyboard events?

    How is it possible to listen to keyboard events, as the depressed return key?  I understand the class ReturnKeyType does not yet work for the QNX InputText component, but even when it's that I'm not sure it will include keyboard events or if it will just be a Visual change to the BACKSPACE on the keyboard.

    I intend using the class flash.text.TextField (for portability) instead of qnx.ui.text.InputText.  Currently, the keyboard will activate and disappear the flash.text.TextField receives or loses the focus.  However, these text fields are the fields of data entry, so I would listen to the back of the key on the keyboard so that I may as well save entered data and remove the keyboard of the screen - or perhaps more simply, just leave the text field to listen to when it loses focus to save the data and allow the keyboard to disappear.  But how do I activate either by pressing back on the keyboard?

    Hey David,

    You can achieve this by using a listener to listen to the keys on your input object as a textfield and response following which keys are pressed. in your case you would listen for the Enter key and perform your actions like taking the focus and the keyboard on the screen. You can use the program below as a reference as to how this can be done:

    package
    {
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.KeyboardEvent;
        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
        import flash.text.TextFieldType;
        import flash.ui.Keyboard;
    
        [SWF(width="1024",height="600",backgroundColor="#CCCCCC",frameRate="30")]
        public class TextFieldTest extends Sprite
        {
    
            private var myInput:TextField;
    
            public function TextFieldTest()
            {
                super();
    
                // support autoOrients
                stage.align = StageAlign.TOP_LEFT;
                stage.scaleMode = StageScaleMode.NO_SCALE;
    
                myInput = new TextField();
                myInput.width = 300;
                myInput.height = 50;
                myInput.type = TextFieldType.INPUT;
    
                /*
                 * listen for what keys are being pressed and react with
                 * onKeyDown function
                */
                myInput.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
    
                addChild(myInput);
    
            }
            private function onKeyDown(e:KeyboardEvent):void
            {
                /*
                 * You can listen for any key presses under the
                 * flash.ui.Keyboard class. it has all the constants
                 * such as .ENTER, .END, etc
                */
                if (e.keyCode == Keyboard.ENTER)
                {
                    trace("You just entered");
    
                    /*
                     * Steal focus away from the textfield object
                     * focus can be set to anywhere and the keyboard
                     * will disappear
                    */
    
                    stage.focus = null;
    
                    /*
                     * Perform other actions such as saving data
                    */
                }
            }
    
        }
    }
    

    hope that helps. Good luck!

  • Sniff for PrintScreen. In Windows 8 blocked keyboard events, monitor what task is to the point.

    In God we trust.

    Good day, everyone.

    My application designed to block the screen capture. It is based on the events of keyboard hook.

    In Windows 8 my callback function is not called, when the monitor of the task is in short.

    I save my callback function with:

    lowLevelKybdHook_ = SetWindowsHookEx ( WH_KEYBOARD_LL, (HOOKPROC): MyCallbackFunction, hInstance, 0);

    It works perfectly in Windows 7 for all cases.

    Windows 8:

    -He works when the monitor of the task is not open.

    -It works, when Task Monitor is opened, not to the point.

    -It does NOT works when the monitor task in short, i.e. my callback function is not called when the task to monitor is the currently selected window.

    -Continue to work (to be called), when the monitor of the task is not to the point.

    I tried to use RegisterHotKey instead SetWindowsHookEx, it has the same effect.

    Any idea?

    Thank you in advance,

    Israel

    PS: I see the same effect with Microsoft Spy ++.
    Keyboard events are blocked, when Microsoft Spy ++ open and in focus.

    Hello Israel,

    Welcome to the Microsoft community.

    Your question of Windows is more complex than what is generally answered in the Microsoft Answers forum. It is better you post the same query in the Microsoft Developer Community. You can get more effective suggestions and adapted by experts familiar with this topic.

    You can also consult the following link:

    https://social.msdn.Microsoft.com/forums/en-us/4cda8492-df2e-4D6F-8eee-4b85c491a493/packet-sniffing?Forum=netfxnetcom

    Hope the helps of information. Let us know if you need help with Windows related issues. We will be happy to help you.

    Thank you

  • Global keyboard event listener?

    Is it possible to create a global keyboard event listener that is unrelated to a window, button, or other user interface element?  The best I could get to add the event to the window listener.  This only works if the window is active.  If the user clicks outside the window and then the receiver for the keyboard does not work.  In addition, when the dialog box appears first of all, it won't work until after the user has made some type of interaction with the window.  I want is to have keyboard shortcuts for users that work regardless of the place where they clicked on the screen, even if the dialogue window is not 'active'.  Is this possible?

    Here is the code I use to the receiver of keyboard for the window.

    mywindow.addEventListener ("keydown", function (k) {keyListen(k)});
    function keyListen(k){if(k.keyName=="Z"){alert("Do stuff here");}}
    

    I don't think that you can create listeners of world events, as for the first appearance of the dialog box, I solved this problem in my script: scripts buliarca BCM_ExtendShortcuts UI by a button activates the event listener to this button. A problem with attach listeners to window, it's in CC2015 events can only be attached to controls and not windows. Setting for windows works in CS6...

  • Keyboard event handler

    I want to process keyboard events and execute a method on every key stroke. It works, but the value sent is a character behind what is actually typed

    < af:resource type = "javascript" >

    function doSomething (evt) {}

    var _keyCode = evt.getKeyCode ();

    model var = evt.getSource ();

    Alert (COMP.getSubmittedValue ())

    AdfCustomEvent.queue (comp, "KeyboardEvent",

    {

    FValue: comp.getSubmittedValue)

    },

    (false);

    evt. Cancel();

    }

    < / af:resource >

    < af:inputText label = "Label 1" id = "it1' autoSubmit ="true">

    < af:clientListener type = "keyPress" method = "doSomething" / >

    < af:serverListener type = "KeyboardEvent" method="#{pageFlowScope.myBean.handleKeyboardEvent}"/ >

    < / af:inputText >

    So, if I type

    ADF

    The first time I will get an empty string, the second time 'a' and the last time "ad".

    Is there a way to get the current value?

    JDev 11.1.2.4

    My work now code I used the keyPressed instead of keyUp event. So now, getSubmittedValue returns the correct value.

    I can't use autosuggest because what the user types is not the value that is to be submitted. For example, the user is looking for a phone country code, it will start to type Ger and the suggested value is Germany + 49 but the value which should be in the form is + 49 and not Germany + 49.

  • If (child on screen) AS3 {play child} (keyboard.event)

    Maby someone can help me with this? :

    I have this script:

    var answerA:Array = [];

    function answerF(answerS:String,x:int,y:int,space:int):void {}

    stiff var: int = answerS.length;

    Word of the var: int;

    If ((answerS.length % 2) == 0) {}

    Word = (((raides * 150) + ((raides-1) * space)) / 2-150);

    } else {}

    Word = (((raides-1) * 150) + ((raides-1) * space)) / 2) - 75;

    }

    var nextX:int = x - Word;

    var C: Class;

    var letter: MovieClip;

    for (var i: int = 0; i < answerS.length; i ++) {}

    C = Class (getDefinitionByName (answerS.charAt (i)));

    Letter = new C();

    addChild (letter);

    answerA.push (letter);

    letter.x = nextX;

    letter.y = y;

    nextX += letter.width + space;

    }

    }

    On the library, I have objects whose names A, B, C, D, E, f... to Z

    This script adds letters from the library. With this script all ok it works perfectly for me, but I want keyboard event for each letter to play but now I don't know how to do this.


    I have a script:


    stage.addEventListener (KeyboardEvent.KEY_DOWN, AKeyDown);

    function AKeyDown(event:KeyboardEvent):void {}

    If (event.keyCode == Keyboard.A) {}

    A.Play ();

    }

    }

    This script works then object instance name.

    And I want to do:

    stage.addEventListener (KeyboardEvent.KEY_DOWN, AKeyDown);

    function AKeyDown(event:KeyboardEvent):void {}

    If (event.keyCode == Keyboard.A) {}

    If child with class name an exist on screen}

    playing the object with the name of class A


    } else {}

    var erreur.r: Sound = new eror();

    errorR.play (0, 1);

    }

    }

    }

    What you need to do, is to give each child a name as you load them.  Then, you can target with their name property.

    var C: Class;

    var letter: MovieClip;

    for (var i: int = 0; i<>

    C = Class (getDefinitionByName (answerS.charAt (i)));

    Letter = new C();

    letter. Name = answerS.charAt (i);

    addChild (letter);

    answerA.push (letter);

    letter.x = nextX;

    letter.y = y;

    nextX += letter.width + space;

    }

    }

    stage.addEventListener (KeyboardEvent.KEY_DOWN, AKeyDown);

    function AKeyDown(event:KeyboardEvent):void {}

    trace ("key pressed:" + string.fromCharCode(0)) (event.charCode));
    var ltr:MovieClip = MovieClip (getChildByName (string.fromCharCode(0)) (event.charCode)));
    LTR. Play();

    }

    You will probably need to convert the string.fromCharCode(0)) (event.charCode) uppercase if you are naming them with capital letters.

  • Keyboard events can be captured by our plugins?

    My plugin runs through the paths of PDEPage and the elements, placing those surrounded by the classic rubberband rectangle in the Windows Clipboard. In short, it implements the copy half an installation "copy / paste".

    Sometimes, the user may choose to type Ctrl-A to select a maximum rectangle.

    Is this possible? How?

    TIA

    If you have a custom tool is active, your tool can register for keyboard events.

  • sequence of images, add the keyboard event loop?

    Hi all

    I have a sequence of 3d images that I want to run with the mouse and drag.

    So far I succeeded with that.

    Also added keyboard event.

    stage.addEventListener (KeyboardEvent.KEY_DOWN, keyPressed);

    function keyPressed(event:KeyboardEvent):void
    {
    If (event.keyCode is 39)
    {
    images_mc.gotoAndStop (images_mc.currentFrame + 1);
    }
    Else if (event.keyCode == 37)
    {
    images_mc.gotoAndStop (images_mc.currentFrame - 1);
    }
    }

    I tried looping event, that is, playing continuously until the button is pressed.

    Help, please.

    Thanks in advance.

    function keyPressed(event:KeyboardEvent):void

    {

    If (event.keyCode is 39)

    {

    If (images_mc.currentFrame<>

    images_mc.gotoAndStop (images_mc.currentFrame + 1);

    }

    else {}

    images_mc.gotoAndStop (1);

    }

    Else if (event.keyCode == 37)

    {

    {if(images_mc.currentFrame>1)}

    images_mc.gotoAndStop (images_mc.currentFrame - 1);

    }

    else {}

    images_mc.gotoAndStop (images_mc.totalFrames);

    }

    }

    }

  • Help with keyboard events

    Hi, I'm a rhythm box design in flash pro Cs6 actionscript 3.0 and I am trying to add a keyboard event that will trigger a key event that I have created loan, I can create the event to play the sound, but is not what I want, can I call for the button click event moves on the key event triggering the sound Here is an example of one of my buttons... code btn, thanks if anyone can help.

    import flash.events.KeyboardEvent;

    /*

    playsound2.fla

    PlaySound with additional features:

    Added TextBox.

    Display the ID3 information

    */

    btn.addEventListener (MouseEvent.CLICK, playSomeSound);

    function playSomeSound(e:MouseEvent)

    {

    var req:URLRequest = new URLRequest ("Savage.mp3");

    var s:Sound = new Sound (req);

    s.addEventListener (Event.COMPLETE, onSoundLoaded);

    s.addEventListener (Event.ID3, onID3Info);

    }

    function onSoundLoaded(event:Event):void

    {

    var localSound:Sound = event.target as Sound;

    localSound.play ();

    }

    function onID3Info(e:Event):void

    {

    var id3Props:ID3Info = e.target.id3;

    var sOut:String = txt.text = "";

    for (var propName:String in id3Props)

    {

    sOut = propName "=" + id3Props [propName] + "\n";

    trace (sOut);

    txt.appendText (sOut);

    }

    txt. Text = id3Props.comment;

    }

    var ba: ByteArray = new ByteArray();

    var gr:Sprite = new Sprite();

    Gr.x = 5;

    Gr.y = 50;

    addChild (gr);

    var time: Timer = new Timer (50);

    time.addEventListener (TimerEvent.TIMER, timerHandler);

    Time.Start ();

    function timerHandler(event:TimerEvent):void

    {

    SoundMixer.computeSpectrum (ba, false);

    var i: int;

    Gr.Graphics.Clear ();

    gr.graphics.lineStyle (2, 0xFF0000);

    gr.graphics.beginFill (0x00ff00);

    gr.graphics.moveTo (10, 10);

    Draw a circle. ;

    var w: uint = 15;

    for (i = 0; I < 512; i += w)

    {

    var t:Number = ba.readFloat ();

    var n: Number = (t * 200);

    gr.graphics.drawCircle (i, 0, - n);

    }

    }

    You can use the following to trigger your button event:

    btn.dispatchEvent (new MouseEvent (MouseEvent.CLICK));

  • Error 1119: Access of a property may not set with a keyboard event

    Scene 1, Layer 'layer 1', frame 1, line 5.1119: access of property may be undefined LEFT through a reference with static type class.
    Scene 1, Layer 'layer 1', frame 1, line 6.1119: access of property may not set down through a reference with static type class.
    Scene 1, Layer 'layer 1', frame 1, line 7.1119: access of possibly undefined property BACK through a reference with static type class.
    Scene 1, Layer 'layer 1', frame 1, line 8.1119: access of property may not set through a reference with static type class.

    I think that to have public but do not know how the value Keyboard.Event.LEFT, UP, DOWN, RIGHT.

    import flash.events.KeyboardEvent;

    stage.addEventListener (KeyboardEvent.LEFT, characterMove);

    stage.addEventListener (KeyboardEvent.DOWN, characterMove); ------Headphones of events for left keyboard etc.

    stage.addEventListener (KeyboardEvent.UP, characterMove);

    stage.addEventListener (KeyboardEvent.RIGHT, characterMove);

    new audience; function characterMove(evt:KeyboardEvent):void {------function to move the person}

    Switch (evt.keyCode) {}

    case Keyboard.LEFT:

    Person.x-= 20;

    case Keyboard.RIGHT:

    Person.x += 20;

    case Keyboard.DOWN:

    Person.y-= 20;

    case Keyboard.UP:

    Person.y += 20;

    by default:

    trace ("keyboard event error")

    }

    }

    Your listeners must specify KeyboardEvents and upward, DOWN, LEFT, RIGHT aren't KeyboardEvents, they are key keyboard codes.  Using KEY_UP and KEY_DOWN instead of each of them in the headphones.

  • Send the keyboard event of the clip loaded by the parent mouse click

    Hello. I'm building a swf wrapper that loads the third-party swf games. The customer wants a button in the package, that will send a keyboard event in the loaded swf file.

    Can someone give me hand on how to build an event to send in the wrapper which penetrates into the loaded swf file?

    Thank you very much!

    After that is finished loading:

    MovieClip (yourloader.content) .dispatchEvent (new KeyboardEvent (somekeyboardevent));   If the loaded swf file is a movieclip

  • With the help of a keyboard event to play a different scene

    I want the user of my game to be able to press the space bar and to be considered as a new scene. I know how to do this with a button, but I can't understand the code to use for a keyboard event.

    Can someone help me understand how pressing the SPACEBAR reading a new scene?

    If the intention is really to stop at these images, use gotoAndStop(), gotoAndPlay() instead.  If you say something to gotoAndPlay where it already, is any stop() command that you could have in this context is already sold out, to run.

  • A function can receive from a keyboard event or a mouse event or there may be only one?

    I decided to add some keyboard functions to my program.  All my functions, I wrote require a mouse event to pass to them.  I wonder if there is a better way to perform these functions of mouse event rather than take the contents of these functions and create a function that is called in a mouse event function OR a function of keyboard events.

    What I mean is that I begin to change the functions of mouse event that I don't have only one line inside of them, which runs a separate function. This same separate function that I run using a keyboard to input as well.  It seems a little redundant to me. Any thoughts?  Thank you.

    In addition to other comments, since MouseEvent and KeyboardEvent extends event, you can type argument as event:

    function myHandler(e:Event):void {}

    code

    }

    The only problem with this is that if you write code within the listener based on a specific event parameter - you will need to mount e argument as such in any case.

    Another solution would be to make argument an object. In this case to the compilation and runtime it will be perceived as valid a data type:

    function myHandler(e:Object):void {}

    code

    }

    Typing is no argument at all (like e: *) can cause inconvenience more typing at least to the object.

  • Keyboard event!

    Hello

    I want to create a keyboard event listener in a flex air application. When I try to launch the application it popup a message and says:

    TypeError: Error #1009: cannot access a property or method of a null object reference.
    hand / windowedapplication1_creationCompleteHandler () [F:\Flex Project\experiment\Capture keyboard Input\src\Main.mxml:19]
    hand / ___Main_WindowedApplication1_creationComplete () [F:\Flex Project\experiment\Capture keyboard Input\src\Main.mxml:4]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent() [E:\dev\4.0.0\frameworks\projects\framework\src\mx\co re\UIComponent.as:12266]
    to mx.core::UIComponent / set initialized() [E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:1577]
    at mx.managers::LayoutManager/doPhasedInstantiation() [E:\dev\4.0.0\frameworks\projects\frame work\src\mx\managers\LayoutManager.as:759]
    at mx.managers::LayoutManager/doPhasedInstantiationCallback() [E:\dev\4.0.0\frameworks\projec ts\framework\src\mx\managers\LayoutManager.as:1072]

    I don't know what I did wrong.

    Here's my code for the application:

    <? XML version = "1.0" encoding = "utf-8"? >
    " < = xmlns:fx s:WindowedApplication ' http://ns.Adobe.com/MXML/2009 "
    xmlns:s = "library://ns.adobe.com/flex/spark".
    xmlns:MX = "library://ns.adobe.com/flex/mx" creationComplete = "windowedapplication1_creationCompleteHandler (event)" >
    < fx:Declarations >
    <! - Place non-visual elements (e.g., services, items of value) here - >
    < / fx:Declarations >
    < fx:Script >
    <! [CDATA]
    Import mx.events.FlexEvent;
    public void handleKeyDown(event:KeyboardEvent): void
    {
    Display.Text = "key has been pressed:"+ event.keyCode;»
    }

    protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
    {
    stage.addEventListener (KeyboardEvent.KEY_DOWN, handleKeyDown);
    }

    []] >
    < / fx:Script >
    < s:Label id = "Display" / >
    < / s:WindowedApplication >

    Hope you can help me to find out why it didn't work. Thank you.

    You use the incorrect event. Change to applicationComplete creationComplete and it will work.

    Kind regards

    Select this option.

  • Keyboard event listener does not work in the browser

    Is there a reason why a keyboard event listener would not work if the flash is embedded in an HTML element? The rest of my game runs well in the background, but I can't launch the movieClip "nextCar." My code is below, if that makes a difference...

    goNow function (event: KeyboardEvent): void {}
    thisOtherKey = event.keyCode;
    If (thisOtherKey == 32) {}
    nextCar.gotoAndPlay (2);
    parkingQue.play ();
    tent ++;
    }
    }
    stage.addEventListener (KeyboardEvent.KEY_DOWN, goNow);

    This is perhaps a silly question, but have you tried to click on your swf file once it opens in the browser and then try the keyboard controls?

    I don't know any problems that may cause debugging workwhen event listeners, but not in a browser.  So I think that maybe your just not well centered on the swf.

  • Can't cancel a keyboard event


    Events (keydown, keyup) keyboard, are not cancellable. Why not?

    I want to make a box TextInput, in which it is impossible to nothing but type numbers. Looks like a pretty good idea, right? He cannot do in Flex 2. Anyone know a work around?

    Can't say much about the cancelable keyboard events, but if you want to limit the keyboard entry for as numbers, just that:

    myText.Restrict = "0-9";

Maybe you are looking for