Keyboard-Events in Console

Hi,

at the moment i write a small MP3 player based on SDL_sound.
I work on Linux and do NOT open a window at the moment.

I want my program to check for keyboard events, but the sequence
i normally use does not seem to work, can anybody confirm
this?

while(!stop) {

while(SDL_PollEvent(&event)) {
  if(event.type == SDL_QUIT) {
stop = 1;
  }

  if(event.key.state == SDL_PRESSED) {
switch(event.key.keysym.sym) {
case SDLK_ESCAPE:
  stop = 1;
  break;

case SDLK_0:
  break;

What do i need to do to make this work?

Best regards,
Torsten.

Torsten Mohr wrote:

at the moment i write a small MP3 player based on SDL_sound.
I work on Linux and do NOT open a window at the moment.

SDL uses the underlying OS to process events. on linux for example this
is usually X11. if you do not open a window, X11 cann not pass events to
SDL. instead keyboard events are captured by the terminal or console
and get sent to the application on stdin. but just reading from stdin
might be a problem because the terminal will buffer your keypresses 'til
it gets a [RETURNN]. i have some code that might come in handy on this:

http://1541.org/public/terminal.c
http://1541.org/public/terminal.h

this code is GPL. just in case … :slight_smile:

best regards …
clemens

Thanks for that code.

I also had some termios code available, but it did not work out
of the box, maybe some other interference with SDL(?).

So now i just open a small window, just to capture key events.

Would it make sense to add some code to SDL?

SDL is great not just for programming games, but also for
processing images and sound.

Best regards,
Torsten.> Torsten Mohr <@Torsten_Mohr> wrote:

at the moment i write a small MP3 player based on SDL_sound.
I work on Linux and do NOT open a window at the moment.

SDL uses the underlying OS to process events. on linux for example this
is usually X11. if you do not open a window, X11 cann not pass events to
SDL. instead keyboard events are captured by the terminal or console
and get sent to the application on stdin. but just reading from stdin
might be a problem because the terminal will buffer your keypresses 'til
it gets a [RETURNN]. i have some code that might come in handy on this:

http://1541.org/public/terminal.c
http://1541.org/public/terminal.h

this code is GPL. just in case … :slight_smile:

best regards …
clemens


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl