Skip to content

Instantly share code, notes, and snippets.

@slime73
Created April 25, 2013 23:07
Show Gist options
  • Save slime73/5463971 to your computer and use it in GitHub Desktop.
Save slime73/5463971 to your computer and use it in GitHub Desktop.
#include <SDL.h>
int PollEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_ENTER)
printf("Mouse focus gained\n");
else if (event.window.event == SDL_WINDOWEVENT_LEAVE)
printf("Mouse focus lost\n");
break;
case SDL_MOUSEMOTION:
printf("relative mm: %d, %d\n", event.motion.xrel, event.motion.yrel);
break;
case SDL_QUIT:
return 1;
default:
break;
}
}
return 0;
}
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
SDL_Window *win = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, 0);
SDL_SetRelativeMouseMode(SDL_TRUE);
while (1)
{
if (PollEvents())
break;
SDL_Delay(10);
}
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment