[SDL] mouse n00b

Kostas Kostiadis kos at climaxgroup.com
Thu Jan 6 08:50:52 PST 2005

ahem...ignore me...just came across this:

"If the cursor is hidden (SDL_ShowCursor(0)) and the input is grabbed
then the mouse will give relative motion events even when the cursor reaches
the edge fo the screen. 
This is currently only implemented on Windows and Linux/Unix-a-likes."



It seems to sort out both my problems...


-----Original Message-----
From: sdl-bounces+kos=climaxgroup.com at libsdl.org
[mailto:sdl-bounces+kos=climaxgroup.com at libsdl.org]On Behalf Of Kostas
Sent: 06 January 2005 11:37
To: SDL list (E-mail)
Subject: [SDL] mouse n00b

Hello all,

Been looking through the docs, and chapter 3 (input handling)
has a bunch of stuff about keyb and joysticks, but nothing on mice...
Are there any docs out there for mice handling?

Anyway, I've just started doing some mouse stuff and I've got a couple of
To make things easier to explain, assume the mouse is used to control
a camera.

1) When running on windowed mode, if the mouse is outside the app window
and you slowly bring it in, the minute it enters the window (it doens't
if you've got focus yet or not) the xrel/yrel values that are reported are
This causes the camera to jerk quite badly...
I could use the SDL_ACTIVEEVENT to zero the mouse inputs for this given tick
but I'm not sure if there are any guarantees about the order events get
In other words if you have something like

SDL_Event event;

while (SDL_PollEvent(&event))
	switch (event.type)
		// if the mouse just entered the window, reset mouse inputs

		// store mouse motion stuff

This will only work if SDL_ACTIVEEVENT is reported AFTER SDL_MOUSEMOTION.
Tbh, it doesn't really matter what order events get reported...As long as
order is always the same you can make this work...
The main question is: are the events ALWAYS GUARANTEED to be reported in 
the same order?

2) When the cursor hits the edge of the window (in this case when running in
fullscreen mode) you can't get any more info for xrel/yrel.  How can I:

+ hide the mouse cursor
+ every tick grab the mouse and force it to be in the middle of the screen
   (so that I can always have valid xrel/yrel values)

thanx in advance,

SDL mailing list
SDL at libsdl.org

More information about the SDL mailing list