int __cdecl _getche_nolock ( void ) { int ch; /* character read */ /* * check pushback buffer (chbuf) a for character. if found, return * it without echoing. */ if ( chbuf != EOF ) { /* * something there, clear buffer and return the character. */ ch = (unsigned char)(chbuf & 0xFF); chbuf = EOF; return ch; } ch = _getch_nolock(); /* read character */ if (ch != EOF) { if (_putch_nolock(ch) != EOF) { return ch; /* if no error, return char */ } } return EOF; /* get or put failed, return EOF */ }
void ThreadUserInput::run() { while (!m_stop) { //see if user wants to go anywhere char val = _getch_nolock(); { //scoped to gurantee mutex unlock std::lock_guard<std::mutex> guard(instance_lock); mChar = val; } } }
// These functions read a single character from the console. _getch() does not // echo the character; _getche() does echo the character. If the push-back // buffer is nonempty, the buffered character is returned immediately, without // being echoed. // // On success, the read character is returned; on failure, EOF is returned. extern "C" int __cdecl _getch() { __acrt_lock(__acrt_conio_lock); int result = 0; __try { result = _getch_nolock(); } __finally { __acrt_unlock(__acrt_conio_lock); } return result; }
int __cdecl _getch ( void ) { int ch; _mlock(_CONIO_LOCK); /* secure the console lock */ __TRY ch = _getch_nolock(); /* input the character */ __FINALLY _munlock(_CONIO_LOCK); /* release the console lock */ __END_TRY_FINALLY return ch; }
extern "C" int __cdecl _getche_nolock() { // Check the pushback buffer for a character. If one is present, return // it without echoing: if (chbuf != EOF) { int const c = static_cast<unsigned char>(chbuf & 0xff); chbuf = EOF; return c; } // Otherwise, read the next character from the console and echo it: int const c = _getch_nolock(); if (c == EOF) return EOF; if (_putch_nolock(c) == EOF) return EOF; return c; }