"GetNumberOfConsoleInputEvents" never 0?
Sergey Okhapkin
sos@prospect.com.ru
Sat Mar 1 01:56:00 GMT 1997
Peter Dalgaard BSA wrote:
> Does this have anything to do with the character composition bug?
> (I.e. dead keys not working - tilde/backquote gone on my keyboard)
You mean entering "national" characters with ascii code > 128? This is a
bug of Windows 95. There are two methods to read keyboard in Win32 API -
ReadFile() (ReadConsole()) and ReadConsoleInput(). The first (two) calls
allows entering such characters, but "filters" non-ascii keys (arrows,
F-keys, etc.). ReadConsoleInput() allows to read functional keys but
keyboard layout switcher doesn't work on Win95 with this call! There is no
problems with NT. I used the following work-around in my programs on Win95:
/*
* int ReadKey (void) - reads console input (including function
* keys and national characters).
* Return value:
* ASCII character (OEM codepage) in low byte
* Virtual Keycode of function key in high byte if low byte == 0.
* BUGS:
* This function does not filter keyboard layout switching
* hot keys.
*
* Original design by Boris Usievich.
* Custom implementation by Sergey Okhapkin
*/
#include <windows.h>
int ReadKey()
{
INPUT_RECORD irBuffer;
DWORD n;
int ch;
HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleMode(hIn, ENABLE_PROCESSED_INPUT);
do {
PeekConsoleInput(hIn, &irBuffer, 1, &n);
if (n==0) {
Sleep(100);
continue;
}
if (irBuffer.EventType == KEY_EVENT &&
irBuffer.Event.KeyEvent.bKeyDown) {
if (irBuffer.Event.KeyEvent.uChar.AsciiChar != '\0') {
ReadConsole(hIn, &ch, 1, &n, NULL);
return ch & 0xff;
} else {
ReadConsoleInput(hIn, &irBuffer, 1, &n);
return irBuffer.Event.KeyEvent.wVirtualKeyCode << 8;
};
} else
ReadConsoleInput(hIn, &irBuffer, 1, &n);
} while (TRUE);
}
#include <stdio.h>
void main()
{
int ch;
for(;;) {
if ((ch = ReadKey()) & 0xff)
printf("%c", ch);
else
printf("VK_%d", (ch >> 8) & 0xff);
}
}
--
Sergey Okhapkin
Moscow, Russia
Looking for a job
-
For help on using this list, send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".
More information about the Cygwin
mailing list