| eventstructure | Description |
|---|---|
| SDL_NOEVENT | Whenever the user is not raising an actual event. |
| SDL_ACTIVEEVENT | Notices if application is active or inactive (for example when you switch to another windowed application and your applications gets into the background or gets minimized). |
| SDL_KEYDOWN | Both have the same record structure (tSDL_KEYBOARDEVENT) which stores the triggering key with state SDL_PRESSED or SDL_RELEASED |
| SDL_KEYUP | |
| SDL_MOUSEMOTION | Notices the movement of the mouse cursor and stores it position and the relative movement from former origin. |
| SDL_MOUSEBUTTONDOWN | Both have the same record structure (tSDL_MOUSEBUTTONEVENT) which stores the triggering mouse and its key with state SDL_PRESSED or SDL_RELEASED. Futhermore the position is stored. |
| SDL_MOUSEBUTTONUP | |
| SDL_JOYAXISMOTION | Notices the usage of the stick of a joystick. |
| SDL_JOYBALLMOTION | Notices the usage of a joyball and the relative movement from its origin. |
| SDL_JOYHATMOTION | Notices the triggering joystick and its hat. Furthermore one of the nine positions is stored (1=up, 2=right upper corner, 3=right and so on; 0=center). |
| SDL_JOYBUTTONDOWN | Both have the same record structure (tSDL_JOYBUTTONEVENT) which stores the triggering joystick and its key with state SDL_PRESSED or SDL_RELEASED. |
| SDL_JOYBUTTONUP | |
| SDL_VIDEORESIZE | Notices when apllication window gets resized and stores the new height and width. |
| SDL_QUITEV | Notices when user quits the application (by clicking application's X-button at right upper corner) |
| SDL_USEREVENT | Unedfined event which can be definied by user. |
| SDL_SYSWMEVENT | Notices system window manager events. |
PROGRAM chap6_1;
USES SDL;
VAR
screen:pSDL_SURFACE;
loopstop:boolean=FALSE;
test_event:pSDL_EVENT;
BEGIN
SDL_INIT(SDL_INIT_VIDEO);
screen:=SDL_SETVIDEOMODE(200,200,32,SDL_SWSURFACE);
IF screen=NIL THEN HALT;
NEW(test_event);
WHILE loopstop=FALSE DO
BEGIN
IF SDL_POLLEVENT(test_event)=1 THEN
BEGIN
write('pending event: ');
CASE test_event^.type_ OF
SDL_ACTIVEEVENT: writeln('Application is/is not active');
SDL_KEYDOWN: BEGIN
write('Key pressed ');
writeln('(SDLKey=',test_event^.key.keysym.sym,')');
{SDLKey 27 = ESCAPE}
IF test_event^.key.keysym.sym=27 THEN loopstop:=TRUE;
END;
SDL_KEYUP: writeln('Key released');
SDL_MOUSEMOTION: writeln('Mouse motion');
SDL_MOUSEBUTTONDOWN: writeln('Mouse button down');
SDL_MOUSEBUTTONUP: writeln ('Mouse button up');
SDL_JOYAXISMOTION: writeln ('Joystick axis motion');
SDL_JOYBALLMOTION: writeln('Joystickïs trackball motion');
SDL_JOYHATMOTION: writeln('Joystickïs hat position changed');
SDL_JOYBUTTONDOWN: writeln('Joystick button pressed');
SDL_JOYBUTTONUP: writeln('Joystick button released');
SDL_QUITEV: writeln('User-requested quit');
END;
END
ELSE writeln('no pending events');
SDL_DELAY(150);
END;
DISPOSE(test_event);
SDL_FREESURFACE(screen);
SDL_QUIT;
END.
|
PROGRAM chap6_1; USES SDL; VAR screen:pSDL_SURFACE; loopstop:boolean=FALSE; test_event:pSDL_EVENT; BEGIN SDL_INIT(SDL_INIT_VIDEO); screen:=SDL_SETVIDEOMODE(200,200,32,SDL_SWSURFACE); IF screen=NIL THEN HALT; NEW(test_event); |
WHILE loopstop=FALSE DO
BEGIN
IF SDL_POLLEVENT(test_event)=1 THEN
BEGIN
write('pending event: ');
|
CASE test_event^.type_ OF
SDL_ACTIVEEVENT: writeln('Application is/is not active');
SDL_KEYDOWN: BEGIN
write('Key pressed ');
writeln('(SDLKey=',test_event^.key.keysym.sym,')');
{SDLKey 27 = ESCAPE}
IF test_event^.key.keysym.sym=27 THEN loopstop:=TRUE;
END;
SDL_KEYUP: writeln('Key released');
SDL_MOUSEMOTION: writeln('Mouse motion');
SDL_MOUSEBUTTONDOWN: writeln('Mouse button down');
SDL_MOUSEBUTTONUP: writeln ('Mouse button up');
SDL_JOYAXISMOTION: writeln ('Joystick axis motion');
SDL_JOYBALLMOTION: writeln('Joystickïs trackball motion');
SDL_JOYHATMOTION: writeln('Joystickïs hat position changed');
SDL_JOYBUTTONDOWN: writeln('Joystick button pressed');
SDL_JOYBUTTONUP: writeln('Joystick button released');
SDL_QUITEV: writeln('User-requested quit');
END;
END
|
ELSE writeln('no pending events');
SDL_DELAY(150);
END;
DISPOSE(test_event);
SDL_FREESURFACE(screen);
SDL_QUIT;
END.
|
PROGRAM chap6_2;
USES SDL;
VAR
screen:pSDL_SURFACE;
loopstop:boolean=FALSE;
test_event:pSDL_EVENT;
PROCEDURE mouse_check;
BEGIN
writeln('X: ',test_event^.motion.x,' Y: ',test_event^.motion.y,
' dX: ',test_event^.motion.xrel,' dY: ',test_event^.motion.yrel,
' button state: ',test_event^.motion.state);
writeln('button state (pressed/released): ',test_event^.button.state,
' button index: ',test_event^.button.button);
END;
BEGIN
SDL_INIT(SDL_INIT_VIDEO);
screen:=SDL_SETVIDEOMODE(200,200,32,SDL_SWSURFACE);
IF screen=NIL THEN HALT;
NEW(test_event);
SDL_EVENTSTATE(SDL_ACTIVEEVENT,SDL_DISABLE);
WHILE loopstop=FALSE DO
BEGIN
IF SDL_POLLEVENT(test_event)=1 THEN
BEGIN
CASE test_event^.type_ OF
SDL_ACTIVEEVENT: writeln('Application is/is not active');
SDL_KEYDOWN: {SDLKey 27 = ESCAPE}
IF test_event^.key.keysym.sym=27 THEN loopstop:=TRUE;
SDL_MOUSEMOTION: mouse_check;
SDL_MOUSEBUTTONDOWN: mouse_check;
SDL_MOUSEBUTTONUP: mouse_check;
END;
END;
END;
DISPOSE(test_event);
SDL_FREESURFACE(screen);
SDL_QUIT;
END.
|
PROGRAM chap6_2;
USES SDL;
VAR
screen:pSDL_SURFACE;
loopstop:boolean=FALSE;
test_event:pSDL_EVENT;
PROCEDURE mouse_check;
BEGIN
writeln('X: ',test_event^.motion.x,' Y: ',test_event^.motion.y,
' dX: ',test_event^.motion.xrel,' dY: ',test_event^.motion.yrel,
' button state: ',test_event^.motion.state);
writeln('button state (pressed/released): ',test_event^.button.state,
' button index: ',test_event^.button.button);
END;
BEGIN
SDL_INIT(SDL_INIT_VIDEO);
screen:=SDL_SETVIDEOMODE(200,200,32,SDL_SWSURFACE);
IF screen=NIL THEN HALT;
NEW(test_event);
|
SDL_EVENTSTATE(SDL_ACTIVEEVENT,SDL_DISABLE); |
WHILE loopstop=FALSE DO
BEGIN
IF SDL_POLLEVENT(test_event)=1 THEN
BEGIN
CASE test_event^.type_ OF
SDL_ACTIVEEVENT: writeln('Application is/is not active');
SDL_KEYDOWN: {SDLKey 27 = ESCAPE}
IF test_event^.key.keysym.sym=27 THEN loopstop:=TRUE;
SDL_MOUSEMOTION: mouse_check;
SDL_MOUSEBUTTONDOWN: mouse_check;
SDL_MOUSEBUTTONUP: mouse_check;
END;
END;
END;
DISPOSE(test_event);
SDL_FREESURFACE(screen);
SDL_QUIT;
END.
|
![]() |
The final result should look and behave like this: While being with the mouse onto the SDL application window any event from the keyboard is recognized and it is said what exactly happened (button down, up, ...) |
![]() |
The final result should look and behave like this: While being with the mouse onto the SDL application window any event from the mouse is recognized and its (x/y) position, the difference between last recognized position and new position (dX and dY) and if a button is pressed or released and the corresponding button's index is shown. |