5 std::cout <<
"Keyboard object created, echo disabled" << std::endl;
9 tcgetattr(STDIN_FILENO, &original);
15 tcsetattr(STDIN_FILENO, TCSANOW, &
noecho);
19 std::cout <<
"Keyboard object deleted, echo enabled" << std::endl;
20 tcsetattr(STDIN_FILENO, TCSANOW, &original);
33 char ch = fgetc(stdin);
64 std::cout << std::endl
65 <<
"Q PRESSED, EXITING PROGRAM " 80 <<
"PRESSED A " << std::endl;
84 <<
"PRESSED S " << std::endl;
88 <<
"PRESSED D " << std::endl;
92 <<
"PRESSED W " << std::endl;
96 <<
"PRESSED X " << std::endl;
131 FD_SET(STDIN_FILENO, &fds);
132 select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv);
133 return FD_ISSET(STDIN_FILENO, &fds);
136 struct termios ttystate;
139 tcgetattr(STDIN_FILENO, &ttystate);
143 ttystate.c_lflag &= ~ICANON;
145 ttystate.c_cc[VMIN] = 1;
148 ttystate.c_lflag |= ICANON;
151 tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
void setKeys()
reads one character from stdin and updates coresponding key state (if one occured) ...
key_states getStates()
getter method for key_states.
void updateInput()
defintion of <class>Input</class> pure virtual function. Updates the keyboard input devices memory st...
bool getS()
Getter method for private S key state.
bool getA()
Getter method for private A key state.
Keyboard()
Construct a new keyboard object.
bool getD()
Getter method for private D key state.
bool getX()
Getter method for private X key state.
void clearCurrentStates()
clear the current key state variables
void printPressed()
Helper method, prints current keys registered as pressed.
int kbhit()
Check if keyboard has been hit - is stdin active.
void setKeyboardActive(int value)
setter method for keyboard active flag, set by kbhit function.
struct termios original noecho
Termios structs for turning on and off terminal echo.
void nonblock(int state)
Configure stdin to be nonblocking to rest of program.
bool getQ()
Getter method for private Q key state.
int getKeyboardActive()
getter method for keyboard active flag, set by kbhit function.
Struct listing the Keys which exist on a Keyboard.
bool getW()
Getter method for private W key state.
key_states currentKeyStates