当前位置: 首页>>代码示例>>C++>>正文


C++ FlushConsoleInputBuffer函数代码示例

本文整理汇总了C++中FlushConsoleInputBuffer函数的典型用法代码示例。如果您正苦于以下问题:C++ FlushConsoleInputBuffer函数的具体用法?C++ FlushConsoleInputBuffer怎么用?C++ FlushConsoleInputBuffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FlushConsoleInputBuffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: noecho_fgets

static int noecho_fgets(char *buf, int size, FILE *tty)
{
    int i;
    char *p;

    p=buf;
    for (;;)
    {
        if (size == 0)
        {
            *p='\0';
            break;
        }
        size--;
#ifdef WIN16TTY
        i=_inchar();
#elif defined(_WIN32)
        i=_getch();
#else
        i=getch();
#endif
        if (i == '\r') i='\n';
        *(p++)=i;
        if (i == '\n')
        {
            *p='\0';
            break;
        }
    }
#ifdef WIN_CONSOLE_BUG
    /* Win95 has several evil console bugs: one of these is that the
     * last character read using getch() is passed to the next read: this is
     * usually a CR so this can be trouble. No STDIO fix seems to work but
     * flushing the console appears to do the trick.
     */
    {
        HANDLE inh;
        inh = GetStdHandle(STD_INPUT_HANDLE);
        FlushConsoleInputBuffer(inh);
    }
#endif
    return(strlen(buf));
}
开发者ID:srinivenkat,项目名称:Parallel_Open_SSL,代码行数:43,代码来源:ui_openssl.c

示例2: wait_for_console_key

/* Read console events until there is a key event.  Also returns on any error. */
static void wait_for_console_key(void)
{
	HANDLE hConsoleInput = GetStdHandle(STD_INPUT_HANDLE);

	if (!ELEM(hConsoleInput, NULL, INVALID_HANDLE_VALUE) && FlushConsoleInputBuffer(hConsoleInput)) {
		for (;;) {
			INPUT_RECORD buffer;
			DWORD ignored;

			if (!ReadConsoleInput(hConsoleInput, &buffer, 1, &ignored)) {
				break;
			}

			if (buffer.EventType == KEY_EVENT) {
				break;
			}
		}
	}
}
开发者ID:Walid-Shouman,项目名称:Blender,代码行数:20,代码来源:wm_init_exit.c

示例3: while

void BaseApp::Run()
{
	CStopwatch timer;
	int sum = 0;
	int counter = 0;

	int deltaTime = 0;
	while (1)
	{
		timer.Start();
		if (kbhit())
		{
			KeyPressed (getch());
			if (!FlushConsoleInputBuffer(mConsoleIn))
				cout<<"FlushConsoleInputBuffer failed with error "<<GetLastError();
		}

		UpdateF((float)deltaTime / 1000.0f);
		Render();
		Sleep(1);

		while (1)
		{
			deltaTime = timer.Now();
			if (deltaTime > 20)
				break;
		}

		sum += deltaTime;
		counter++;
		if (sum >= 1000)
		{
			TCHAR  szbuff[255];
			StringCchPrintf(szbuff, 255, TEXT("FPS: %d"), counter);
			SetConsoleTitle(szbuff);

			counter = 0;
			sum = 0;
		}
	}
}
开发者ID:ShartepStudy,项目名称:LUXOFT,代码行数:41,代码来源:BaseApp.cpp

示例4: sprintf

void CMap::CheckForNpc(int x, int y)
{
	// Go through all of the npcs and see if we have a match for the position
	for(int i = 0; i < (int)m_vNpcs.size(); i++)
	{
		CNpc *pNpc= &m_vNpcs[i];

		// Check if this npc has the same position as the position passed in
		if(x == pNpc->GetIndex().X && y == pNpc->GetIndex().Y)
		{
			// Move the player back so they aren't on the NPC
			g_Player.MovePlayerBack();


//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

			// Since we have cut scenes and eventual shop keepers, we first check
			// to see if there is any action key assigned with the npc before we
			// let them speak.  If they do, we want to use that dialog and not
			// the standard dialog that they would spit out.  Like Jax's case.
			if(pNpc->GetActionKey())
			{
				// Handle the action key and return
				g_ActionKeys.HandleKey(pNpc->GetActionKey(), pNpc);
				return;
			}

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////


			// Display the NPC message, pause, then clear the input buffer and wait for a key
			char szDialog[5000] = {0};
			sprintf(szDialog, "%s: %s", pNpc->GetName(), pNpc->GetMessage());
			DisplayDialog(szDialog);
			Sleep(1000);
			FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
			getch();
			break;
		}
	}
}
开发者ID:88er,项目名称:tutorials,代码行数:41,代码来源:Map.cpp

示例5: CON_Init

/*
==================
CON_Init
==================
*/
void CON_Init( void )
{
	CONSOLE_SCREEN_BUFFER_INFO info;
	char consoleTitle[128];
	int i;

	// handle Ctrl-C or other console termination
	SetConsoleCtrlHandler( CON_CtrlHandler, TRUE );

	qconsole_hin = GetStdHandle( STD_INPUT_HANDLE );
	if( qconsole_hin == INVALID_HANDLE_VALUE )
		return;

	qconsole_hout = GetStdHandle( STD_OUTPUT_HANDLE );
	if( qconsole_hout == INVALID_HANDLE_VALUE )
		return;

	GetConsoleMode( qconsole_hin, &qconsole_orig_mode );

	// allow mouse wheel scrolling
	SetConsoleMode( qconsole_hin,
		qconsole_orig_mode & ~ENABLE_MOUSE_INPUT );

	FlushConsoleInputBuffer( qconsole_hin ); 

	GetConsoleScreenBufferInfo( qconsole_hout, &info );
	qconsole_attrib = info.wAttributes;
	qconsole_backgroundAttrib = qconsole_attrib & (BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED|BACKGROUND_INTENSITY);

	// ZTM: FIXME: com_productName isn't initialized or set to game title yet.
	Com_sprintf( consoleTitle, sizeof (consoleTitle), "%s Dedicated Server Console", com_productName ? com_productName->string : PRODUCT_NAME );
	SetConsoleTitle( consoleTitle );

	// initialize history
	for( i = 0; i < QCONSOLE_HISTORY; i++ )
		qconsole_history[ i ][ 0 ] = '\0';

	// set text color to white
	SetConsoleTextAttribute( qconsole_hout, CON_ColorCharToAttrib( COLOR_WHITE ) );
}
开发者ID:mecwerks,项目名称:spearmint,代码行数:45,代码来源:con_win32.c

示例6: input_waiting

bool input_waiting()
{
#ifndef WIN32
    fd_set readfds;
    struct timeval tv;
    FD_ZERO(&readfds);
    FD_SET(fileno(stdin), &readfds);
    tv.tv_sec = 0;
    tv.tv_usec = 0;
    select(16, &readfds, nullptr, nullptr, &tv);

    return (FD_ISSET(fileno(stdin), &readfds));
#else
    static int init = 0, pipe;
    static HANDLE inh;
    DWORD dw;

    if(!init)
    {
        init = 1;
        inh = GetStdHandle(STD_INPUT_HANDLE);
        pipe = !GetConsoleMode(inh, &dw);
        if(!pipe)
        {
            SetConsoleMode(inh, dw & ~(ENABLE_MOUSE_INPUT|ENABLE_WINDOW_INPUT));
            FlushConsoleInputBuffer(inh);
        }
    }
    if(pipe)
    {
        if(!PeekNamedPipe(inh, NULL, 0, NULL, &dw, NULL)) return 1;
        return dw;
    }
    else
    {
        GetNumberOfConsoleInputEvents(inh, &dw);
        return dw <= 1 ? 0 : dw;
    }
#endif // WIN32
}
开发者ID:ServerTech,项目名称:cortex,代码行数:40,代码来源:misc.cpp

示例7: CON_Init

/*
==================
CON_Init
==================
*/
void CON_Init( void )
{
	CONSOLE_CURSOR_INFO curs;
	CONSOLE_SCREEN_BUFFER_INFO info;
	int i;

	// handle Ctrl-C or other console termination
	SetConsoleCtrlHandler( CON_CtrlHandler, TRUE );

	qconsole_hin = GetStdHandle( STD_INPUT_HANDLE );
	if( qconsole_hin == INVALID_HANDLE_VALUE )
		return;

	qconsole_hout = GetStdHandle( STD_OUTPUT_HANDLE );
	if( qconsole_hout == INVALID_HANDLE_VALUE )
		return;

	GetConsoleMode( qconsole_hin, &qconsole_orig_mode );

	// allow mouse wheel scrolling
	SetConsoleMode( qconsole_hin,
		qconsole_orig_mode & ~ENABLE_MOUSE_INPUT );

	FlushConsoleInputBuffer( qconsole_hin ); 

	GetConsoleScreenBufferInfo( qconsole_hout, &info );
	qconsole_attrib = info.wAttributes;

	SetConsoleTitle("ioquake3 Dedicated Server Console");

	// make cursor invisible
	GetConsoleCursorInfo( qconsole_hout, &qconsole_orig_cursorinfo );
	curs.dwSize = 1;
	curs.bVisible = FALSE;
	SetConsoleCursorInfo( qconsole_hout, &curs );

	// initialize history
	for( i = 0; i < QCONSOLE_HISTORY; i++ )
		qconsole_history[ i ][ 0 ] = '\0';
}
开发者ID:AbandonedCart,项目名称:XperiaPlayNative,代码行数:45,代码来源:con_win32.c

示例8: getKey

int getKey()
{
	int key; DWORD cNumRead; INPUT_RECORD irInBuf;
	HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);

	do
	{
		FlushConsoleInputBuffer(hStdIn);
		do
		{
			ReadConsoleInput(hStdIn, &irInBuf, 1, &cNumRead);
		} while (irInBuf.EventType != KEY_EVENT || irInBuf.Event.KeyEvent.bKeyDown);
		if (irInBuf.Event.KeyEvent.uChar.AsciiChar == 0)
		{
			key = irInBuf.Event.KeyEvent.wVirtualKeyCode;
		}
		else key = irInBuf.Event.KeyEvent.uChar.AsciiChar;
	} while (key != ESCAPE && key != LEFT && key != UP
		&& key != RIGHT  && key != DOWN && key != ENTER);

	return key;
}
开发者ID:vigonz06,项目名称:Correo,代码行数:22,代码来源:utilsWin.cpp

示例9: GetStdInputHandle

void FileTests::TestReadFileLine()
{
    HANDLE const hIn = GetStdInputHandle();
    VERIFY_IS_NOT_NULL(hIn, L"Verify we have the standard input handle.");

    DWORD dwMode = ENABLE_LINE_INPUT;
    VERIFY_WIN32_BOOL_SUCCEEDED(SetConsoleMode(hIn, dwMode), L"Set input mode for test.");

    VERIFY_WIN32_BOOL_SUCCEEDED(FlushConsoleInputBuffer(hIn), L"Flush input buffer in preparation for test.");

    char ch = '\0';
    Log::Comment(L"Queue background blocking read file operation.");
    auto BackgroundRead = std::async([&] {
        DWORD dwRead = 0;
        VERIFY_WIN32_BOOL_SUCCEEDED(ReadFile(hIn, &ch, 1, &dwRead, nullptr), L"Read file was successful.");
        VERIFY_ARE_EQUAL(1u, dwRead, L"Verify we read 1 character.");
    });

    char const chExpected = 'a';
    Log::Comment(L"Send a key into the console.");
    SendFullKeyStrokeHelper(hIn, chExpected);

    auto status = BackgroundRead.wait_for(std::chrono::milliseconds(250));
    VERIFY_ARE_EQUAL(std::future_status::timeout, status, L"We should still be waiting for a result.");
    VERIFY_ARE_EQUAL('\0', ch, L"Character shouldn't be filled by background read yet.");

    Log::Comment(L"Send a line feed character, we should stay blocked.");
    SendFullKeyStrokeHelper(hIn, '\n');
    status = BackgroundRead.wait_for(std::chrono::milliseconds(250));
    VERIFY_ARE_EQUAL(std::future_status::timeout, status, L"We should still be waiting for a result.");
    VERIFY_ARE_EQUAL('\0', ch, L"Character shouldn't be filled by background read yet.");

    Log::Comment(L"Now send a carriage return into the console to signify the end of the input line.");
    SendFullKeyStrokeHelper(hIn, '\r');

    Log::Comment(L"Wait for background thread to unblock.");
    BackgroundRead.wait();
    VERIFY_ARE_EQUAL(chExpected, ch);
}
开发者ID:ShipRekt101,项目名称:terminal,代码行数:39,代码来源:API_FileTests.cpp

示例10: initializeWorld

void initializeWorld(){
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
	FlushConsoleInputBuffer(hConsole);	
	
	drawTable();
	
	rotatingBar(WIDTH/2, HEIGHT/2, 0);
	
	gotoxy(0,0);
	SetConsoleTextAttribute(hConsole, colors[0]);
	printf("O");
	SetConsoleTextAttribute(hConsole, colors[1]);
	gotoxy(WIDTH,0);
	printf("O");
	SetConsoleTextAttribute(hConsole, colors[2]);
	gotoxy(WIDTH,HEIGHT);
	printf("O");
	SetConsoleTextAttribute(hConsole, colors[3]);
	gotoxy(0,HEIGHT);
	printf("O");
	
}
开发者ID:felipeViana,项目名称:Tron,代码行数:22,代码来源:initialize.cpp

示例11: __declspec

void __declspec(noreturn) exit()
{
//   EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_ENABLED);
   exitflag = 1;
   if (savesndtype)
       savesnddialog();
   if (videosaver_state)
     main_savevideo();  // stop saving video

   if (!normal_exit)
       done_fdd(false);
   done_tape();
   done_dx();
   done_gs();
   done_leds();
   save_nv();
   zf232.rs_close();
   zf232.zf_close();
   done_ie_help();
   done_bpx();
   GdiplusShutdown();

//   timeEndPeriod(1);
   if (ay[1].Chip2203) YM2203Shutdown(ay[1].Chip2203); //Dexus
   if (ay[0].Chip2203) YM2203Shutdown(ay[0].Chip2203); //Dexus
   if (comp.ts.vdac2) vdac2::close_ft8xx();

   color();
   printf("\nsee you later!\n");
   if (!nowait)
   {
       SetConsoleTitle("press a key...");
       FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
       getch();
   }
   fflush(stdout);
   SetConsoleCtrlHandler(ConsoleHandler, FALSE);
   exit(0);
}
开发者ID:tslabs,项目名称:zx-evo,代码行数:39,代码来源:init.cpp

示例12: tty_getchar

int tty_getchar()
{
  HANDLE stdinHandle = GetStdHandle (STD_INPUT_HANDLE);

  DWORD rc = WaitForSingleObject (stdinHandle, 1000);

  if (rc == WAIT_TIMEOUT)   return  0;
  if (rc == WAIT_ABANDONED) return -1;
  if (rc == WAIT_FAILED)    return -1;

  // The whole ReadConsoleInput () part is a workaround.
  // For some unknown reason, maybe a mingw bug, a random signal
  // is sent to stdin which unblocks WaitForSingleObject () and sets rc 0.
  // Then it wants to read with getche () a keyboard input
  // which has never been made.

  INPUT_RECORD buf[100];

  DWORD num = 0;

  memset (buf, 0, sizeof (buf));

  ReadConsoleInput (stdinHandle, buf, 100, &num);

  FlushConsoleInputBuffer (stdinHandle);

  for (DWORD i = 0; i < num; i++)
  {
    if (buf[i].EventType != KEY_EVENT) continue;

    KEY_EVENT_RECORD KeyEvent = buf[i].Event.KeyEvent;

    if (KeyEvent.bKeyDown != TRUE) continue;

    return KeyEvent.uChar.AsciiChar;
  }

  return 0;
}
开发者ID:ghostyguo,项目名称:hashcat,代码行数:39,代码来源:terminal.c

示例13: r_cons_readchar

R_API int r_cons_readchar() {
    char buf[2];
    buf[0] = -1;
#if __WINDOWS__ && !__CYGWIN__ && !MINGW32
    BOOL ret;
    DWORD out;
    DWORD mode;
    char b;
    HANDLE h = GetStdHandle (STD_INPUT_HANDLE);
    GetConsoleMode (h, &mode);
    SetConsoleMode (h, 0); // RAW
ignore:
    if (!I->is_wine) {
        while (!_kbhit ());
        b = getwinkey ();
        if (b=='2')
            goto ignore;
        else if (b=='1')
            ret = ReadConsole (h, buf, 1, &out, NULL);
        else {
            buf[0]=b;
            ret=1;
        }
    } else {
        ret = ReadConsole (h, buf, 1, &out, NULL);
    }
    FlushConsoleInputBuffer(h);
    if (!ret)
        return -1;
    SetConsoleMode (h, mode);
#else
    r_cons_set_raw (1);
    if (read (0, buf, 1)==-1)
        return -1;
    r_cons_set_raw (0);
#endif
    return r_cons_controlz (buf[0]);
}
开发者ID:jasmorton,项目名称:radare2,代码行数:38,代码来源:input.c

示例14: FlushConsoleInputBuffer

bool KConsoleDriver::readKeyExtended(char *out,bool *pressing,int *repeatCount)
{
#ifdef USE_M_API
	INPUT_RECORD inrec;
	dword count;

	FlushConsoleInputBuffer( hStdIn );
	ReadConsoleInput( hStdIn, &inrec, 1, &count );

	if (count > 0)
	{
		if (inrec.EventType == KEY_EVENT)
		{
			*out = inrec.Event.KeyEvent.uChar.AsciiChar;
			*pressing = inrec.Event.KeyEvent.bKeyDown != 0;
			*repeatCount = (int)inrec.Event.KeyEvent.wRepeatCount;
			return true;
		}
	}
#endif
	*out = 0;
	return false;
}
开发者ID:LeDYoM,项目名称:kaste,代码行数:23,代码来源:KConsoleDriver.cpp

示例15: GetStdHandle

void CConsole::initconsole()
{
  conin =  GetStdHandle(STD_INPUT_HANDLE);
  conout = GetStdHandle(STD_OUTPUT_HANDLE);

  ZeroMemory(&ovc,sizeof(ovc));
  ovc.hEvent = CreateEvent(NULL,FALSE,FALSE,NULL);
  if(ovc.hEvent == INVALID_HANDLE_VALUE) {
     throw errors("CreateEvent error");
  }

  SetConsoleMode(conin,ENABLE_MOUSE_INPUT);
  GetConsoleScreenBufferInfo(conout,&csb);
  if (csb.dwSize.X<80||csb.dwSize.Y<25){
     CloseHandle(ovc.hEvent);
     throw errors("console size is too small");
  }
  FlushConsoleInputBuffer(conin);
  head=tail=0;
  cci.bVisible=0;cci.dwSize=10;
  SetConsoleCursorInfo(conout,&cci);
  SetConsoleTitle(jmail);
}
开发者ID:inspirer,项目名称:history,代码行数:23,代码来源:console.cpp


注:本文中的FlushConsoleInputBuffer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。