I'm writing a game in assembly, and I need to check if a key was pressed. So, how is kbhit implemented in Linux?
Thanks.
I'm writing a game in assembly, and I need to check if a key was pressed. So, how is kbhit implemented in Linux?
Thanks.
Google turned up a kbhit implementation for Linux in C: http://cboard.cprogramming.com/c-programming/63166-kbhit-linux.html
You could either compile this as is and call it from your assembly code, or if you really want to you could convert it to assembly.
I tried what you said, but as far as I know linking a c module doesn't mean that the c standard library is linked. Is there another way?
I assume that you want also key releases. I also assume you are on the console (for X, XKeyEvent has enough info).
First, you have to put your terminal (i.e: console) in non-canonical or in raw mode. If you don't do this, you won't see any input until there is a line delimiter or EOF on input. See my answer to your previous question.
Then, to get key releases, you want to set the keyboard to RAW or MEDIUMRAW mode (this has nothing to do with terminal raw mode, this is very Linux and console specific, see console_ioctl(4)). Don't forget to set the keyboard back to its original mode before exiting.
There's a nice article about this here.