本文整理匯總了C++中GetNumberOfConsoleInputEvents函數的典型用法代碼示例。如果您正苦於以下問題:C++ GetNumberOfConsoleInputEvents函數的具體用法?C++ GetNumberOfConsoleInputEvents怎麽用?C++ GetNumberOfConsoleInputEvents使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetNumberOfConsoleInputEvents函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: getch2_enable
void getch2_enable(void)
{
DWORD retval;
in = GetStdHandle(STD_INPUT_HANDLE);
if(!GetNumberOfConsoleInputEvents(in,&retval))
{
printf("getch2: %i can't get number of input events [disabling console input]\n",GetLastError());
getch2_status = 0;
}
else getch2_status=1;
}
示例2: FD_ZERO
bool Utils::input_pending(void) {
#ifdef HAVE_SELECT
fd_set read_fds;
struct timeval timeout;
FD_ZERO(&read_fds);
FD_SET(0,&read_fds);
timeout.tv_sec = timeout.tv_usec = 0;
select(1,&read_fds,NULL,NULL,&timeout);
if (FD_ISSET(0,&read_fds)) {
return true;
} else {
return false;
}
#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)) {
myprintf("Nothing at other end - exiting\n");
exit(EXIT_FAILURE);
}
if (dw) {
return true;
} else {
return false;
}
} else {
if (!GetNumberOfConsoleInputEvents(inh, &dw)) {
myprintf("Nothing at other end - exiting\n");
exit(EXIT_FAILURE);
}
if (dw <= 1) {
return false;
} else {
return true;
}
}
return false;
#endif
}
示例3: GetNumberOfConsoleInputEvents
DWORD CInput::GetInput(){
GetNumberOfConsoleInputEvents(hIn, &read);
if(read){
ReadConsoleInput(hIn, &input, 1, &read);
if(input.EventType == KEY_EVENT && input.Event.KeyEvent.bKeyDown == true){
FlushConsoleInputBuffer(hIn);
read = 0;
return input.Event.KeyEvent.wVirtualKeyCode;
}
}
return 0;
}
示例4: _kbhit_nolock
extern "C" int __cdecl _kbhit_nolock()
{
// If a character has been pushed back, return TRUE:
if (chbuf != -1)
return TRUE;
if (__dcrt_lowio_console_input_handle == -2)
__dcrt_lowio_initialize_console_input();
if (__dcrt_lowio_console_input_handle == -1)
return FALSE;
HANDLE const console_handle = reinterpret_cast<HANDLE>(__dcrt_lowio_console_input_handle);
// Peek at all pending console events:
DWORD num_pending;
if (GetNumberOfConsoleInputEvents(console_handle, &num_pending) == 0)
return FALSE;
if (num_pending == 0)
return FALSE;
__crt_scoped_stack_ptr<INPUT_RECORD> const input_buffer(_malloca_crt_t(INPUT_RECORD, num_pending));
if (input_buffer.get() == nullptr)
return FALSE;
DWORD num_peeked;
if (PeekConsoleInput(console_handle, input_buffer.get(), num_pending, &num_peeked) == 0)
return FALSE;
if (num_peeked == 0 || num_peeked > num_pending)
return FALSE;
// Scan all of the peeked events to determine if any is a key event
// that should be recognized:
for (INPUT_RECORD* p = input_buffer.get(); num_peeked > 0; --num_peeked, ++p)
{
if (p->EventType != KEY_EVENT)
continue;
if (!p->Event.KeyEvent.bKeyDown)
continue;
if (p->Event.KeyEvent.uChar.AsciiChar == 0 &&
_getextendedkeycode(&p->Event.KeyEvent) == nullptr)
continue;
return TRUE;
}
return FALSE;
}
示例5: console_isch
bool console_isch (void)
{
if (console_buffer) {
return 0;
} else if (realconsole) {
return false;
} else if (consoleopen < 0) {
DWORD events = 0;
GetNumberOfConsoleInputEvents (stdinput, &events);
return events > 0;
}
return false;
}
示例6: getEvents
DWORD getEvents(INPUT_RECORD **record)
{
HANDLE rHnd= GetStdHandle(STD_INPUT_HANDLE);
DWORD numEvents=0;
DWORD numEventsRead=0;
GetNumberOfConsoleInputEvents(rHnd, &numEvents);
if(numEvents)
{
*record=new INPUT_RECORD[numEvents];
ReadConsoleInput(rHnd, *record, numEvents, &numEventsRead);
}
return numEventsRead;
}
示例7: GetNumberOfConsoleInputEvents
BOOL THardwareInfo::getKeyEvent( TEvent& event )
{
if( !pendingEvent )
{
GetNumberOfConsoleInputEvents( consoleHandle[cnInput], &pendingEvent );
if( pendingEvent )
ReadConsoleInput( consoleHandle[cnInput], &irBuffer, 1, &pendingEvent );
}
if( pendingEvent )
{
if( irBuffer.EventType == KEY_EVENT && irBuffer.Event.KeyEvent.bKeyDown )
{
event.what = evKeyDown;
event.keyDown.charScan.scanCode = irBuffer.Event.KeyEvent.wVirtualScanCode;
event.keyDown.charScan.charCode = irBuffer.Event.KeyEvent.uChar.AsciiChar;
event.keyDown.controlKeyState = irBuffer.Event.KeyEvent.dwControlKeyState;
/* Convert NT style virtual scan codes to PC BIOS codes.
*/
if( (event.keyDown.controlKeyState & (kbShift | kbAltShift | kbCtrlShift)) != 0 )
{
uchar index = irBuffer.Event.KeyEvent.wVirtualScanCode;
if ((event.keyDown.controlKeyState & kbShift) && ShiftCvt[index] != 0)
event.keyDown.keyCode = ShiftCvt[index];
else if ((event.keyDown.controlKeyState & kbCtrlShift) && CtrlCvt[index] != 0)
event.keyDown.keyCode = CtrlCvt[index];
else if ((event.keyDown.controlKeyState & kbAltShift) && AltCvt[index] != 0)
event.keyDown.keyCode = AltCvt[index];
}
/* Set/Reset insert flag.
*/
if( event.keyDown.keyCode == kbIns )
insertState = !insertState;
if( insertState )
event.keyDown.controlKeyState |= kbInsState;
pendingEvent = 0;
return True;
}
// Ignore all events except mouse events. Pending mouse events will
// be read on the next polling loop.
else if( irBuffer.EventType != MOUSE_EVENT )
pendingEvent = 0;
}
return False;
}
示例8: GetStdHandle
// @author Andre Allan Ponce
// @author Computergeek01 (for the keyboard input stuff)
// @author Duoas (for more keyboard input stuff)
// url: http://www.cplusplus.com/forum/beginner/75529/
// url: http://www.cplusplus.com/forum/articles/7312/#msg33734
void Game::runGame(){
bool running = true;
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
DWORD NumInputs = 0;
DWORD InputsRead = 0;
INPUT_RECORD irInput;
GetNumberOfConsoleInputEvents(hInput, &NumInputs);
int old_state = 0;
clock_t startTime = clock();
while(running){
//printGame();
switch(state){
case STATE_PRE_GAME:{
createWorld();
preGameInit();
state = STATE_LEVEL_ONE;
break;
}
case STATE_GAME_FINISH:{
break;
}
case STATE_WAIT:{
if(clock() - startTime > 20){ // it was too fast at one point
state = old_state;
}
//*/
//Sleep(1*1000);
//state = old_state;
break;
}
default:{
printGame();
do ReadConsoleInput( hInput, &irInput, 1, &InputsRead );
while ((irInput.EventType != KEY_EVENT) || irInput.Event.KeyEvent.bKeyDown);
//ReadConsoleInput(hInput, &irInput, 1, &InputsRead);
startTime = clock();
Location* thisRoom = world[currX][currY];
getKeyInput(irInput.Event.KeyEvent.wVirtualKeyCode, thisRoom);
switch(state){
case STATE_LEVEL_ONE:{
old_state = STATE_LEVEL_ONE;
state = STATE_WAIT;
break;
}
}
break;
}
}
}
}
示例9: WinStatCon
Bool TERMWINDOWMEMBER WinStatCon(void)
{
if (TermWindowCollection.InFocus(this))
{
DWORD Number;
if (GetNumberOfConsoleInputEvents(hConsoleInput, &Number))
{
return (!!Number);
}
}
return (FALSE);
}
示例10: read_input
static void read_input(void)
{
DWORD retval;
HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
/*check if there are input events*/
if (!GetNumberOfConsoleInputEvents(in, &retval))
return;
if (!retval)
return;
/*read all events*/
INPUT_RECORD eventbuffer[128];
if (!ReadConsoleInput(in, eventbuffer, MP_ARRAY_SIZE(eventbuffer), &retval))
return;
/*filter out keyevents*/
for (int i = 0; i < retval; i++) {
switch (eventbuffer[i].EventType) {
case KEY_EVENT: {
KEY_EVENT_RECORD *record = &eventbuffer[i].Event.KeyEvent;
/*only a pressed key is interesting for us*/
if (record->bKeyDown) {
UINT vkey = record->wVirtualKeyCode;
bool ext = record->dwControlKeyState & ENHANCED_KEY;
int mpkey = mp_w32_vkey_to_mpkey(vkey, ext);
if (mpkey) {
mp_input_put_key(input_ctx, mpkey);
} else {
/*only characters should be remaining*/
int c = record->uChar.UnicodeChar;
if (c > 0)
mp_input_put_key(input_ctx, c);
}
}
break;
}
case MOUSE_EVENT:
case WINDOW_BUFFER_SIZE_EVENT:
case FOCUS_EVENT:
case MENU_EVENT:
default:
break;
}
}
return;
}
示例11: check_input
int check_input()
{
DWORD dw_events, dw_bytes;
if (console) {
GetNumberOfConsoleInputEvents(input, &dw_events);
return dw_events > 1;
} else if (bytes_left > 0) {
return 1;
} else if (PeekNamedPipe(input, NULL, 0, NULL, &dw_bytes, NULL)) {
bytes_left = dw_bytes;
return bytes_left > 0;
} else {
return 1;
}
}
示例12: defined
void Keyboard::Flush()
{
#if defined(_MSC_VER)
int nNumberOfEvents = 0;
GetNumberOfConsoleInputEvents(this->m_hStdIn, (LPDWORD)&nNumberOfEvents);
for (int i = 0; i < nNumberOfEvents; i++)
{
INPUT_RECORD buffer = {};
DWORD nNumberOfEventsRead = 0;
ReadConsoleInput(this->m_hStdIn, &buffer, 1, &nNumberOfEventsRead);
}
#endif
}
示例13: PreReadConsoleInput
// Helper function
void PreReadConsoleInput(HANDLE hConIn, DWORD nFlags/*enum CEReadConsoleInputFlags*/, CESERVER_CONSOLE_APP_MAPPING** ppAppMap = NULL)
{
#if defined(_DEBUG) && defined(PRE_PEEK_CONSOLE_INPUT)
INPUT_RECORD ir = {}; DWORD nRead = 0, nBuffer = 0;
BOOL bNumGot = GetNumberOfConsoleInputEvents(hConIn, &nBuffer);
BOOL bConInPeek = nBuffer ? PeekConsoleInputW(hConIn, &ir, 1, &nRead) : FALSE;
#endif
if (gbPowerShellMonitorProgress)
{
CheckPowershellProgressPresence();
}
if (gbCurDirChanged)
{
gbCurDirChanged = false;
if (ghConEmuWndDC)
{
if (gFarMode.cbSize
&& gFarMode.OnCurDirChanged
&& !IsBadCodePtr((FARPROC)gFarMode.OnCurDirChanged))
{
gFarMode.OnCurDirChanged();
}
else
{
CEStr szDir;
if (GetDirectory(szDir) > 0)
{
// Sends CECMD_STORECURDIR into RConServer
SendCurrentDirectory(ghConWnd, szDir);
}
}
}
}
if (!(nFlags & rcif_Peek))
{
// On the one hand - there is a problem with unexpected Enter/Space keypress
// github#19: After executing php.exe from command prompt (it runs by Enter KeyDown)
// the app gets in its input queue unexpected Enter KeyUp
// On the other hand - application must be able to understand if the key was released
// Powershell's 'get-help Get-ChildItem -full | out-host -paging' or Issue 1927 (jilrun.exe)
CESERVER_CONSOLE_APP_MAPPING* pAppMap = UpdateAppMapFlags(nFlags);
if (pAppMap && ppAppMap) *ppAppMap = pAppMap;
}
}
示例14: terminal_setup_getch
void terminal_setup_getch(struct input_ctx *ictx)
{
assert(!running);
HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
if (GetNumberOfConsoleInputEvents(in, &(DWORD){0})) {
input_ctx = ictx;
death = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!death)
return;
if (pthread_create(&input_thread, NULL, input_thread_fn, NULL)) {
CloseHandle(death);
return;
}
running = true;
}
}
示例15: FlushMouseEvents
void FlushMouseEvents()
{
if (ghConWnd)
{
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD nTotal = 0;
if (GetNumberOfConsoleInputEvents(h, &nTotal) && nTotal)
{
INPUT_RECORD *pr = (INPUT_RECORD*)calloc(nTotal, sizeof(*pr));
if (pr && PeekConsoleInput(h, pr, nTotal, &nTotal) && nTotal)
{
bool bHasMouse = false;
DWORD j = 0;
for (DWORD i = 0; i < nTotal; i++)
{
if (pr[i].EventType == MOUSE_EVENT)
{
bHasMouse = true;
continue;
}
else
{
if (i > j)
pr[j] = pr[i];
j++;
}
}
// Если были мышиные события - сбросить их
if (bHasMouse)
{
if (FlushConsoleInputBuffer(h))
{
// Но если были НЕ мышиные - вернуть их в буфер
if (j > 0)
{
WriteConsoleInput(h, pr, j, &nTotal);
}
}
}
}
}
}
}