From: Tobias Leich type
.
active
is used when an event of type SDL_ACTIVEEVENT
is reported.
When the mouse leaves or enters the window area a SDL_APPMOUSEFOCUS
type activation event occurs,
if the mouse entered the window then gain will be 1, otherwise gain will be 0.
key
is used when an event of type SDL_KEYDOWN
or SDL_KEYUP
is reported.
The type and state actually report the same information, they just use different values to do it.
A keyboard event generally occurs when a key is released (type=SDL_KEYUP
or key_state=SDL_RELEASED
)
@@ -265,58 +265,115 @@ These special cases are required for compatibility with Sun workstations.
The scancode
field should generally be left alone, it is the hardware-dependent scancode returned by the keyboard.
The sym
field is extremely useful. It is the SDL-defined value of the key (see the keysym definitions in SDLKey).
+This field is very useful when you are checking for certain key presses, like so:
while(poll_event($event)) + { + switch($event->type) + { + case SDL_KEYDOWN: + move_left() if($event->key_sym == SDLK_LEFT); + break; + . + . + . + } + } + +
mod
stores the current state of the keyboard modifiers as explained in SDL_GetModState.
The unicode
field is only used when UNICODE translation is enabled with SDL_EnableUNICODE.
+If unicode
is non-zero then this is the UNICODE character corresponding to the keypress.
+If the high 9 bits of the character are 0, then this maps to the equivalent ASCII character:
my $char; + if(($event->key_unicode & 0xFF80) == 0) + { + $char = $event->key_unicode & 0x7F; + } + else + { + print("An International Character.\n"); + } + ++
UNICODE translation does create a slight overhead so don't enable it unless its needed.
+NOTE: Key release events (SDL_KEYUP) won't necessarily (ever?) contain unicode information. +See http://lists.libsdl.org/pipermail/sdl-libsdl.org/2005-January/048355.html
Simply put, a SDL_MOUSEMOTION type event occurs when a user moves the mouse within the
+application window or when SDL_WarpMouse is called. Both the absolute (motion_x
and motion_y
)
+and relative (motion_xrel
and motion_yrel
) coordinates are reported along with the current
+button states (motion_state
).
The button state can be interpreted using the SDL_BUTTON
macro (see SDL_GetMouseState).
The X/Y coordinates of the mouse
Relative motion in the X/Y direction.
+If the cursor is hidden (SDL_ShowCursor(0)) and the input is grabbed (SDL_WM_GrabInput(SDL_GRAB_ON)), +then the mouse will give relative motion events even when the cursor reaches the edge of the screen. +This is currently only implemented on Windows and Linux/Unix-alikes.