Haxe + OpenFL-> Neko, MouseEvent.xxxKey is always false

I am making a game using Haxe + OpenFL. I once aimed at js, then switched to neko, and the following construction stopped working:

if(e.shiftKey)
  do smth

Ofc I have not changed this block of code and context since the change of purpose. Something went wrong?

P. S. Tracing shows that holding the alt, ctrl, or shift keys does not change the corresponding properties of the MouseEvent object

+4
source share
1 answer

Based on this link , this was a problem, but was fixed two years ago. Oddly enough, my tests show that it still does not work.

This class demonstrates that it will work correctly in js, but not in neko.

class Main extends Sprite
{

    public function new()
    {
        super();

        var s:Sprite = new Sprite();
        s.graphics.beginFill(0xff0000);
        s.graphics.drawCircle(100, 100, 200);
        s.graphics.endFill();
        addChild(s);

        //testing a simple click event
        s.addEventListener(MouseEvent.CLICK, OnClick);

        //testing wheel events, as I read somewhere it could a been a bug in earlier versions
        s.addEventListener(MouseEvent.MOUSE_WHEEL, OnWheel);

        //testing click events on the stage object, in case it acted differently
        addEventListener(MouseEvent.CLICK, OnStageClick);
    }

    private function OnStageClick(e:MouseEvent):Void 
    {
        trace(e.shiftKey);
    }

    private function OnWheel(e:MouseEvent):Void 
    {
        trace(e.shiftKey);
    }

    private function OnClick(e:MouseEvent):Void 
    {
        trace(e.shiftKey);
    }

}

openfl.events.KeyboardEvent , ( , 16). .

class Main extends Sprite
{
    var shiftIsPressed:Bool = false;
    public function new()
    {
        super();
        stage.addEventListener(KeyboardEvent.KEY_DOWN, OnDown);
        stage.addEventListener(KeyboardEvent.KEY_UP, OnUp);
        stage.addEventListener(MouseEvent.CLICK, OnClick);

    }

    private function OnUp(e:KeyboardEvent):Void 
    {
        if (e.keyCode == 16)
        {
            shiftIsPressed = false;
        }
    }

    private function OnDown(e:KeyboardEvent):Void 
    {
        if (e.keyCode == 16)
        {
            shiftIsPressed = true;
        }

    }

    private function OnClick(e:MouseEvent):Void 
    {
        if (shiftIsPressed)
        {
            trace('Click!');
        }
    }

}

, , , ++. , - , - .

2 (sept 22)

-

+2

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


All Articles