| Summary: | SDL_WarpMouseInWindow has no effect (in Windows 7 at least) | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Adam M. <adam> |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | 2.0.3 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 7 | ||
It turns out that this was caused by running the program in a virtual machine. When I tried running it under a real instance of Windows, it worked fine. |
SDL_WarpMouseInWindow appears to have no effect whatsoever, at least in Windows 7. Look at this sample program. It first attempts to warp the mouse when a window is created. That doesn't work. Then it lets you move the mouse with the arrow keys, which also does nothing. (It prints stuff like "warp from 10,10 to 20,10, producing 10,10", showing that the mouse position isn't even changed internally, let alone on screen.) GetError does not return an error. #define SDL_MAIN_HANDLED #include <SDL.h> #include <stdio.h> int main() { SDL_Init(SDL_INIT_EVENTS|SDL_INIT_VIDEO); SDL_Window *pWindow = SDL_CreateWindow("Window", 100, 100, 400, 300, 0); SDL_WarpMouseInWindow(pWindow, 200, 150); while(true) { SDL_Event e; SDL_WaitEvent(&e); printf("%d\n", e.type); if(e.type == SDL_MOUSEMOTION) printf("%d,%d in window %d\n", e.motion.x, e.motion.y, e.motion.windowID); else if(e.type == SDL_KEYDOWN && e.key.state) { int x, y, ox, oy; SDL_GetMouseState(&x, &y); ox = x, oy = y; if(e.key.keysym.sym == SDLK_LEFT) x -= 10; else if(e.key.keysym.sym == SDLK_RIGHT) x += 10; else if(e.key.keysym.sym == SDLK_UP) y -= 10; else if(e.key.keysym.sym == SDLK_DOWN) y += 10; if(x != ox || y != oy) { int ax, ay; SDL_WarpMouseInWindow(pWindow, x, y); const char *error = SDL_GetError(); if(error && *error) printf("ERROR: %s\n", error); SDL_GetMouseState(&ax, &ay); printf("warp from %d,%d to %d,%d, producing %d,%d\n", ox, oy, x, y, ax, ay); } } else if(e.type == SDL_QUIT) break; } SDL_DestroyWindow(pWindow); SDL_Quit(); return 0; }