Issue - EventListenerMouse help for windows

Issue - EventListenerMouse help for windows

I’ve got an issue with my game. In the Mac version onMouseMove works when the cursor is outside the window which is desired effect. But on PC Window build it doesn’t get any mouse event the second it’s out of the window.

is there a fix for this?

auto _mouseListener = EventListenerMouse::create();
mouseListener->onMouseMove = CC_CALLBACK_1(CombatZoneLayer::onMouseMove, this);
dispatcher->addEventListenerWithSceneGraphPriority(_mouseListener, this);

Side note 1 : ontouchmove works fine (act like it should) outside of the PC window. if there is a way to force and on touchMove callback I could hack fix it.

Side note 2 : tried to get SDL working and it doesn’t get SDL_PollEvent for mouse stuff. I know the SDL_PollEvent works because I have it working for gamepads.

Weird to reply to my own message but maybe someone might have a better answer
I think the core issue is cause by glfwSetCursorPosCallback(); API is acting like its supposed to; which is not right.

still looking for a solution though. Any inside would be helpful.

It seems weird that you would want to capture mouse events outside your app. I mean all apps seem to work this way. If I open Word and move my mouse off the Word window, Word doesn’t capture the events anymore…normal.

Am I misunderstanding something?

The issue is the on a Mac, onMouseMove still give callbacks when the curser is outside the window. Were as PC it doesn’t. It’s the fact that they act differently when they should be acting the same.

For context I’ve made a bullet hell. The fighter uses the curser position. If the player freaks out and move their curser off window, the fighter should follow the desktop position. It does this on Mac; Its smooth and clean. On PC it hard stops the fighter causing the player to possible die.

OnTouchMove still gets callbacks outside of the window for both btw.

SDL has a desktop mouse position. I just can’t use it because it not getting mouse SDL_PollEvent.

I know this is weird issue… I am really not sure what to do.

I see what you wrote now, I confused Windows and Mac, the issue is that your game running on Mac is still receiving callbacks from mouse events even when you are outside your games window.

I eventually figure out a solution so this is just for people who experience the same problem as me and need help.

Here is how you do it.

  1. Create a mouse icon have it follow the mouse position.
    2.In CCGLViewImpl-desktop change your current glfwSetInputMode to this

glfwSetInputMode(_mainWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

this will allow the mouse never to leave the screen and keep get move events.

  1. Lock the mouse position to be within the ruffly with in window frame (offset but set max and min). This will stop the mouse cursor image from running away when you keep moving down.

I recommend using glfwSetInputMode(_mainWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); for all the other time when you don’t need the mouse lock in but still want to see the cursor image.

1 Like