Reputation: 835
I want to be able to change the position of the cursor over my SDL2 window. I can't find anything in the documentation. Is there a way to do it?
Upvotes: 4
Views: 7608
Reputation: 21
Use the SDL_WarpMouseInWindow()
function, it sets the mouse position in the SDL Window.
Demonstration:
auto* WIN = SDL_CreateWindow("text", 0, 0, Width, Height, SDL_WINDOW_RESIZABLE);
SDL_WarpMouseInWindow(WIN, 50, 50);/*sets mouse position to 50, 50 relative to the window */
Keep in mind, this invokes the SDL_MOUSEMOTION
event so, if you're polling events, it will consider the change in mouse position as a mouse movement.
Here's a reference: https://wiki.libsdl.org/SDL_WarpMouseInWindow
Upvotes: 2