Is it possible to know exactly which numpad key is pressed in AS3 (with Num Lock disabled)?

In Actionscript 3, I see that if I press the "8" key (from NumPad) I get the KEYCODE result of the Numpad key "8", but when I turn off "Num Lock" and press the Numpad key "8", the event I get is keyCode up arrow keys ...

How is the difference between the keys of the numeric keypad (with Num Lock disabled) and the original keys, such as arrows, End, Insert, Delete and so on?

I tried using the keyLocationevent property , the value of this property is 0 for arrows and 3 for the numeric keypad, but when Num Lock is disabled, the values ​​for 4, 6, 2, and 8 in numpad are 0, so I can not distinguish between numbers with disabled numpad and keys with arrows.

In addition, the numLockproperty of the Keyboardclass does not work, because I can’t know if I press the up arrow or 8 iota Num Lock turned off (because they cause the same event, or I think that)

+3
source share
4 answers

EDIT:

I see AutoHotkey CAN do this. So it can be done. I was wrong :(.

But again .. It seems that this is not possible inside Flash Player.


I ran several tests, and one in Assembler threw this result to me:

When activating NumLock:

  • Numpad 8 Key: AX=4838
  • Up arrow: AX=4800

With NumLock Disabled:

  • Numpad 8 Key: AX=4800
  • Up arrow: AX=4800

PS: I use INT 16Hit to return (in AX) the KeyCode and ScanCode of the pressed key.

0

, . , key code OS- FLEX . Microsoft Natural iMac ( MS Natural). numlock, key code .

, , , , flex .

:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="onApplicationComplete()" viewSourceURL="srcview/index.html">
    <mx:Script>
        <![CDATA[
            public function onApplicationComplete():void
            {
                stage.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);
            }

            public function onKeyDown(keyboardEvent:KeyboardEvent):void
            {
                charCodeLabel.text = keyboardEvent.charCode.toString();
                keyCodeLabel.text = keyboardEvent.keyCode.toString();
                switch(keyboardEvent.keyLocation)
                {
                    case KeyLocation.LEFT:
                        keyLocationBox.text = "Left";
                        break;
                    case KeyLocation.NUM_PAD:
                        keyLocationBox.text ="Num Pad";
                        break;
                    case KeyLocation.RIGHT:
                        keyLocationBox.text = "Right";
                        break;
                    default:
                        keyLocationBox.text = "Standard";
                }

            }
        ]]>
    </mx:Script>
    <mx:Label x="46" y="34" text="Just click anywhere inside the flash movie and start typing."/>
    <mx:Label x="46" y="72" text="You typed Char Code:"/>
    <mx:Label x="232" y="72" text="Key Code:"/>
    <mx:Label x="183" y="72" id="charCodeLabel"/>
    <mx:Label x="303" y="72" id="keyCodeLabel"/>
    <mx:Label x="46" y="98" text="Key Location:"/>
    <mx:Label x="134" y="98" width="68" id="keyLocationBox"/>

</mx:Application>

, , : Flex Online key code

0

From what I understand, this is not possible due to the differences and limitations between the two different plugin architectures that Flash must support (to work in IE (activeX) and everything else). Sorry - he bites.

0
source

Perhaps this will help you ...

package {
    import flash.utils.Dictionary;
    import flash.ui.Keyboard;
    import flash.events.KeyboardEvent;
    import flash.display.Sprite;

    public class Main extends Sprite {

        private static const _NUMERIC_KEYS:Dictionary=new Dictionary();
        {
        _NUMERIC_KEYS[45]=0;
        _NUMERIC_KEYS[35]=1;
        _NUMERIC_KEYS[40]=2;
        _NUMERIC_KEYS[34]=3;
        _NUMERIC_KEYS[37]=4;
        _NUMERIC_KEYS[12]=5;
        _NUMERIC_KEYS[39]=6;
        _NUMERIC_KEYS[36]=7;
        _NUMERIC_KEYS[38]=8;
        _NUMERIC_KEYS[33]=9;
        }

        public function Main() {
            stage.addEventListener(KeyboardEvent.KEY_UP, stageKeyUp);
        }

        private function stageKeyUp(e : KeyboardEvent) : void {
            if(Keyboard.numLock){
                trace("NumLock ON :",String.fromCharCode(e.charCode));
            }else{
                trace("NumLock OFF :", _NUMERIC_KEYS[e.keyCode]);
            }
        }
    }
}
-1
source

Source: https://habr.com/ru/post/1717435/


All Articles