int main(int argv, char* args[])
{
// Initialize SDL
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
// If SDL for some reason fails to initialize
printf(“Error: failed to initialize SDL\n”);
}
else
{
// Create the SDL window
m_pWindow = SDL_CreateWindow("Mouse position", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
// If the SDL window has been successfully created
if(m_pWindow)
{
// Create the SDL renderer
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, SDL_RENDERER_ACCELERATED);
}
}
while(m_Running)
{
while(SDL_PollEvent(&m_Event))
{
switch(m_Event.type)
{
case SDL_QUIT:
m_Running = false;
case SDL_MOUSEMOTION:
{
m_MouseX = m_Event.motion.x;
m_MouseY = m_Event.motion.y;
break;
}
}
}
// Print out the mouse position in the console
printf("MouseX: %i, MouseY: %i\n", m_MouseX, m_MouseY);
}
// Destroy the SDL renderer
if(m_pRenderer)
SDL_DestroyRenderer(m_pRenderer);
// Destroy the SDL window
if(m_pWindow)
SDL_DestroyWindow(m_pWindow);
// Quit SDL
SDL_Quit();
return 0;
int main(int argv, char* args[])
{
// Initialize SDL
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
// If SDL for some reason fails to initialize
printf(“Error: failed to initialize SDL\n”);
}
else
{
// Create the SDL window
m_pWindow = SDL_CreateWindow("Mouse Position", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
// If the SDL window has been successfully created
if(m_pWindow)
{
// Create the SDL renderer
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, SDL_RENDERER_ACCELERATED);
}
}
while(m_Running)
{
while(SDL_PollEvent(&m_Event))
{
switch(m_Event.type)
{
case SDL_QUIT:
{
m_Running = false;
break;
}
case SDL_MOUSEMOTION:
{
m_MouseX = m_Event.motion.x;
m_MouseY = m_Event.motion.y;
break;
}
}
}
// Print out the mouse position in the console
printf("MouseX: %i, MouseY: %i\n", m_MouseX, m_MouseY);
}
// Destroy the SDL renderer
if(m_pRenderer)
SDL_DestroyRenderer(m_pRenderer);
// Destroy the SDL window
if(m_pWindow)
SDL_DestroyWindow(m_pWindow);
// Quit SDL
SDL_Quit();
return 0;
I really thought this would be replied quickly due to being simple, but it seems its not the case.
Let me re-phrase my question then: Can somebody give me a program, preferably short, that takes raw mouse input and prints it on the screen in some way?