mirror of
https://github.com/reactos/reactos.git
synced 2025-08-02 00:03:22 +00:00
Create a branch for cmake bringup.
svn path=/branches/cmake-bringup/; revision=48236
This commit is contained in:
parent
a28e798006
commit
c424146e2c
20602 changed files with 0 additions and 1140137 deletions
101
lib/sdk/crt/conio/kbhit.c
Normal file
101
lib/sdk/crt/conio/kbhit.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/msvcrt/conio/kbhit.c
|
||||
* PURPOSE: Checks for keyboard hits
|
||||
* PROGRAMERS: Ariadne, Russell
|
||||
* UPDATE HISTORY:
|
||||
* 28/12/98: Created
|
||||
* 27/9/08: An almost 100% working version of _kbhit()
|
||||
*/
|
||||
|
||||
#include <precomp.h>
|
||||
|
||||
static CRITICAL_SECTION CriticalSection;
|
||||
volatile BOOL CriticalSectionInitialized=FALSE;
|
||||
|
||||
/*
|
||||
* FIXME Initial keyboard char not detected on first punch
|
||||
*
|
||||
* @implemented
|
||||
*/
|
||||
|
||||
int _kbhit(void)
|
||||
{
|
||||
PINPUT_RECORD InputRecord = NULL;
|
||||
DWORD NumberRead = 0;
|
||||
DWORD EventsRead = 0;
|
||||
DWORD RecordIndex = 0;
|
||||
DWORD BufferIndex = 0;
|
||||
HANDLE StdInputHandle = 0;
|
||||
DWORD ConsoleInputMode = 0;
|
||||
|
||||
/* Attempt some thread safety */
|
||||
if (!CriticalSectionInitialized)
|
||||
{
|
||||
InitializeCriticalSectionAndSpinCount(&CriticalSection, 0x80000400);
|
||||
CriticalSectionInitialized = TRUE;
|
||||
}
|
||||
|
||||
EnterCriticalSection(&CriticalSection);
|
||||
|
||||
if (char_avail)
|
||||
{
|
||||
LeaveCriticalSection(&CriticalSection);
|
||||
return 1;
|
||||
}
|
||||
|
||||
StdInputHandle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
/* Turn off processed input so we get key modifiers as well */
|
||||
GetConsoleMode(StdInputHandle, &ConsoleInputMode);
|
||||
|
||||
SetConsoleMode(StdInputHandle, ConsoleInputMode & ~ENABLE_PROCESSED_INPUT);
|
||||
|
||||
/* Start the process */
|
||||
if (!GetNumberOfConsoleInputEvents(StdInputHandle, &EventsRead))
|
||||
{
|
||||
LeaveCriticalSection(&CriticalSection);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!EventsRead)
|
||||
{
|
||||
LeaveCriticalSection(&CriticalSection);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(InputRecord = (PINPUT_RECORD)malloc(EventsRead * sizeof(INPUT_RECORD))))
|
||||
{
|
||||
LeaveCriticalSection(&CriticalSection);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ReadConsoleInput(StdInputHandle, InputRecord, EventsRead, &NumberRead))
|
||||
{
|
||||
free(InputRecord);
|
||||
LeaveCriticalSection(&CriticalSection);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (RecordIndex = 0; RecordIndex < NumberRead; RecordIndex++)
|
||||
{
|
||||
if (InputRecord[RecordIndex].EventType == KEY_EVENT &&
|
||||
InputRecord[RecordIndex].Event.KeyEvent.bKeyDown)
|
||||
{
|
||||
BufferIndex = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(InputRecord);
|
||||
|
||||
/* Restore console input mode */
|
||||
SetConsoleMode(StdInputHandle, ConsoleInputMode);
|
||||
|
||||
LeaveCriticalSection(&CriticalSection);
|
||||
|
||||
return BufferIndex;
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue