mouseeventhaxeshiftopenflneko

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


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

if(e.shiftKey)
  do smth

Ofc I've not changed this block of code, nor context since changing the target. What has gone wrong?

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


Solution

  • Based on this link, it used to be a problem, but has been fixed two years ago. Strangely, my tests show it still doesn't 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);
        }
    
    }
    

    An alternative solution could be to use openfl.events.KeyboardEvent and note when the shift key is up or down as a boolean (note that shift's keycode is 16). This example works correctly in my tests.

    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!');
            }
        }
    
    }
    

    Update

    Since I've always used the keyboard event trick I mentioned earlier, I missed the fact that it also does not work in C++. I suppose those two targets use some custom event system and someone forgot to register the modifier keys to the created event.

    Update 2 (sept 22)

    Someone fixed it