Reading Keystrokes asynchroniously under linux

Started by
6 comments, last by directNoob 16 years ago
Hi. I need to read key strokes under linux and the os is not running on x86 hardware. Does anyone know how to do that? Thank alex
Advertisement
I don't know if this helps, but I found the following with a little searching:

http://www.ibm.com/developerworks/linux/library/l-async/
There was a saying we had in college: Those who walk into the engineering building are never quite the same when they walk out.
select on unixlikes work on any filedescriptor not just network sockets. You can use stdin as the descriptor in select to allow non-blocking input.
Hi.

Thank for your reply.
As you correctly figured out, Im using C/C++, but
@Telastyn:
As Im am a really linux noob, can you specify what you mean?!
Is select a commend line command?

@medevilenemy:
Seams to be a good resource. Thanks.
But I first have to look over it.

Thanks
Alex
Quote:Original post by directNoob
As Im am a really linux noob, can you specify what you mean?!
Is select a commend line command?


select is a system call. man 2 select has more information

You can find a decent tutorial at
http://beej.us/guide/bgnet
Hi.

Thanks for this tip and the link.

Alex
Quote:Original post by directNoob
I need to read key strokes under linux and the os is not running on x86 hardware.
Does anyone know how to do that?


Correct answer: write a device driver and add it to the kernel, preferrably as a module.

Using one of the select() family (select(), poll(), epoll(), etc) can be used to read from stdin on some other file descriptor in non-blocking mode. If you read from stdin you're getting input cooked by the tty driver. You can use fcntl() to adjust the tty to deliver raw data instead of cooked data, but you're still not reading keystrokes, you're getting, um, sushi (as in, it's raw data that's been prepared by an expert).

The only way to actually read keystrokes is to talk to the keyboard device directly, which can only be done from kernel mode. Unless you're using, say, a USB keyboard or a dumb terminal over a serial line (remember the days!) or maybe a remote user channeling X over SSH.

My guess is what you really want is a stty()/select() kind of combo to read the raw data from stdin. There are libraries that will do that for you (eg. ncurses, SDL, X11).

Stephen M. Webb
Professional Free Software Developer

Hi, thanks.

I tried SDL, direcfb. I need it on the ps3 but I cant compile it due to compile errors.
Im absolutly at the end of everything.
Nothing goes right. Just error messages. And nobody seems to have errors using sdl on ps3 except me.

I just need user response to end the application. But Im absolutely not able to solve this problem. Why?!

Thanks

This topic is closed to new replies.

Advertisement