foft
Certified Guru
I'm pulling my hair out trying to read characters from the keyboard! All I want is a nice simple way to find out which keys are currently pressed (unbuffered press/release events also ok) under Linux. I don't want to use SDL or some heavyweight library. There MUST be a simple way of doing this since its pretty much a core OS function!
Closest I've found is:
CODE
#include <stdio.h>
#include <termios.h>
#include <sys/ioctl.h>
main()
{
struct termios ts;
struct termios new_ts;
ioctl(0, TCGETS, &ts);
new_ts = ts;
new_ts.c_lflag &= !ICANON;
new_ts.c_lflag &= !ECHO;
ioctl(0, TCSETS, &new_ts);
char c=0;
while (c!='q')
{
c=getchar();
printf("%c\n",c);
}
ioctl(0, TCSETS, &ts);
}
Which is still rubbish since I want to know everything that is pressed at the current time. Or as a minimum an event on press/release of each key.
Any advice greatfully appreciated. Someone kindly sent me a Cradle to fix TVout/keyboard/joystick on Atari800. TVout was simple due to Kounch's work. Keyboard is proving hard - spent a few hours on it so far - to read a keyboard :angry: Any good (multiple) joystick code/suggestions also greatly appreciated.
Thanks,
Mark
Closest I've found is:
CODE
#include <stdio.h>
#include <termios.h>
#include <sys/ioctl.h>
main()
{
struct termios ts;
struct termios new_ts;
ioctl(0, TCGETS, &ts);
new_ts = ts;
new_ts.c_lflag &= !ICANON;
new_ts.c_lflag &= !ECHO;
ioctl(0, TCSETS, &new_ts);
char c=0;
while (c!='q')
{
c=getchar();
printf("%c\n",c);
}
ioctl(0, TCSETS, &ts);
}
Which is still rubbish since I want to know everything that is pressed at the current time. Or as a minimum an event on press/release of each key.
Any advice greatfully appreciated. Someone kindly sent me a Cradle to fix TVout/keyboard/joystick on Atari800. TVout was simple due to Kounch's work. Keyboard is proving hard - spent a few hours on it so far - to read a keyboard :angry: Any good (multiple) joystick code/suggestions also greatly appreciated.
Thanks,
Mark