Detecting cursor left the window



  • Hi, would love to know if there's a way to listen for when the mouse cursor left the game window?

    Thanks!


  • administrators

    You can attach a MOUSE_LEAVE event to the stage like Flixel does in FlxMouse: https://github.com/HaxeFlixel/flixel/blob/4.1.1/flixel/input/mouse/FlxMouse.hx#L319



  • Sadly that doesn't seem to work for me, tried it on flash, neko and windows and the listener method seems to never be called.

    Not sure what the issue might be, but even doing a simple trace in the FlxMouse onMouseLeave method doesn't show anything. Other events like the different onDowns work just fine

    Any ideas?


  • administrators

    I'm not sure if it works outside of Flash, but on Flash it definitely works:



  • Apparently I didn't have FlashDevelop well setup to get Flash's console log, doing a FLxG.log.add() as in your example does work on flash, but seems like there's no such luck on cpp targets.

    I'm currently locking the cursor as posted here, but would be great to see if there's a similar solution or a similar way to track the cursor position relative to the screen instead of the game and maybe check myself if the cursor is inside the window or not


Log in to reply