This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: "GetNumberOfConsoleInputEvents" never 0?

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;



  do {
    PeekConsoleInput(hIn, &irBuffer, 1, &n);
    if (n==0) {

    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);
			printf("VK_%d", (ch >> 8) & 0xff);

Sergey Okhapkin
Moscow, Russia
Looking for a job

For help on using this list, send a message to
"" with one line of text: "help".

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]