int getKeyVal(){ int retval = KEYS_TOTAL; int wait_for_input = 1; while(wait_for_input == 1) { retval = keypress_handler(); if(retval != KEYS_TOTAL) wait_for_input = 0; } return retval; }
static int handle_keypress_handlers(SDL_Event *e){ if(e->type == SDL_KEYDOWN){ keypress_handler_t *h; h = keypress_handler(e); if(h != NULL){ if(h->timer == 0) add_keypress_timer(h, e); h->callback(e); } } else if (e->type == SDL_KEYUP){ keypress_handler_t *h; h = keypress_handler(e); if(h != NULL) remove_keypress_timer(h); } return 0; }
int getKeyVal() { struct timespec tsp={0,500}; struct termios term_vals; struct termios * term_ptr = &term_vals; int wait_for_input = 1; int fd_terminal = fileno( stdin ); int retval = KEYS_TOTAL; unsigned char keypress[0]; fflush(stdout); //write everything prior to clearing terminal if(!isSetTerminalToHideInput(fd_terminal, term_ptr)) exit(1); //set terminal values to new settings while(wait_for_input == 1) { nanosleep(&tsp, NULL); //check later retval = keypress_handler(fd_terminal, keypress); if(retval != KEYS_TOTAL) wait_for_input = 0; } if( tcsetattr(fd_terminal, TCSADRAIN, term_ptr) == -1 ) exit(1); //reset terminal values to the original settings return retval; }