46#if LASS_PLATFORM_TYPE == LASS_PLATFORM_TYPE_WIN32
47# define LASS_IO_KEYBOARD_HAVE_WIN32
49#elif LASS_HAVE_TERMIOS_H && LASS_HAVE_SYS_IOCTL_H
50# define LASS_IO_KEYBOARD_HAVE_TERMIOS_H_AND_IOCTL_H
52# include <sys/ioctl.h>
53# if LASS_HAVE_UNISTD_H
56# if LASS_HAVE_SYS_SOCKET_H
57# include <sys/socket.h>
59# if LASS_HAVE_SYS_FILIO_H
60# include <sys/filio.h>
64# error lass/io/keyboard.cpp not supported
73#if defined(LASS_IO_KEYBOARD_HAVE_TERMIOS_H_AND_IOCTL_H)
76 class TerminalAttributeSaver
79 TerminalAttributeSaver()
81 LASS_ENFORCE_CLIB(tcgetattr(STDIN_FILENO, &savedAttributes_));
83 ~TerminalAttributeSaver()
85 const int rc = tcsetattr(STDIN_FILENO, TCSANOW, &savedAttributes_);
89 const int errnum = util::impl::lass_errno();
90 std::cerr <<
"[LASS RUN MSG] UNDEFINED BEHAVIOUR WARNING: "
91 <<
"failed to restore terminal attributes: ("
92 << errnum <<
") " << util::impl::lass_strerror(errnum)
96 const termios& savedAttributes()
const
98 return savedAttributes_;
101 termios savedAttributes_;
111#if defined(LASS_IO_KEYBOARD_HAVE_WIN32)
112 return _kbhit() != 0;
113#elif defined(LASS_IO_KEYBOARD_HAVE_TERMIOS_H_AND_IOCTL_H)
114 impl::TerminalAttributeSaver attributeSaver;
115 termios rawMode = attributeSaver.savedAttributes();
116 rawMode.c_lflag &= ~static_cast<tcflag_t>(ICANON);
117 LASS_ENFORCE_CLIB(tcsetattr(STDIN_FILENO, TCSANOW, &rawMode));
120 LASS_ENFORCE_CLIB(ioctl(STDIN_FILENO, FIONREAD, &count));
123# error keyboardIsHit not supported
132#if defined(LASS_IO_KEYBOARD_HAVE_WIN32)
134#elif defined(LASS_IO_KEYBOARD_HAVE_TERMIOS_H_AND_IOCTL_H)
135 impl::TerminalAttributeSaver attributeSaver;
136 termios rawMode = attributeSaver.savedAttributes();
137 rawMode.c_lflag &= ~static_cast<tcflag_t>(ICANON);
138 rawMode.c_lflag &= ~static_cast<tcflag_t>(ECHO);
139 rawMode.c_cc[VMIN] = 1;
140 rawMode.c_cc[VTIME] = 0;
141 LASS_ENFORCE_CLIB(tcsetattr(STDIN_FILENO, TCSANOW, &rawMode));
143 unsigned char character = 0;
144 const ssize_t charactersRead = LASS_ENFORCE_CLIB(read(STDIN_FILENO, &character, 1));
145 LASS_ENFORCE(charactersRead == 1);
146 return static_cast<int>(character);
148# error keyboardIsHit not supported
bool keyboardIsHit()
return true if a key is pressed and which is waiting in the buffer ...
int keyboardGetKey()
get a character from the console without echo
streams, binary streams, vrmlstreams, ...
Library for Assembled Shared Sources.