Altera_Forum
Honored Contributor
20 years agoKey pressed?
Hello!
How can I check if a key was pressed? I didn't found a appropriate function in the C which is used by Microtronix. Bye, Lothar.Hello!
How can I check if a key was pressed? I didn't found a appropriate function in the C which is used by Microtronix. Bye, Lothar.Are you referring to a key press at the console? ... like fgetc() ?
Hi!
fgetc() is not a solution for me, because I only have to check if key was pressed or not. And fgetc() is waiting for a key. Bye, Lothar.Hi
There are a few choices of what you can do here. One is to use the inl() functions defined in linux/io.h or asm/io.h. You will have to include the nios system header file for the io structures you want to use and the base address of the buttons. The second and better 'Linux way' I would say is edit the existing altera_pio_buttons.c (or something like that) in drivers/char/ with adding support for ioctl() commands. Here you would place the inl() functions. There is a thread where I asked about drivers ect where you can find a link to some documentation on Linux device drivers. There are a lot of links here on drivers, makefiles ect. Good luck. RualHi Lothar,
> fgetc() is not a solution for me, because I only have to check if key was > pressed or not. Okay ... I'll take a giant step into the abstract ;-) and just assume you're referring to a serial device, consonle, pty, etc. rather than some sort of custom keypad or custom hardware: You can use the select() system call with an appropriate timeout. If you just want to poll, set the timeout to zero. Regards, --Scott