Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ios> // Required for streamsize
- #include <iostream>
- #include <istream>
- #include <windows.h> // Required for numeric_limits
- bool getconchar( KEY_EVENT_RECORD& krec )
- {
- DWORD cc;
- INPUT_RECORD irec;
- HANDLE h = GetStdHandle( STD_INPUT_HANDLE );
- if (h == NULL)
- {
- return false; // console not found
- }
- for( ; ; )
- {
- ReadConsoleInput( h, &irec, 1, &cc );
- if( irec.EventType == KEY_EVENT
- && ((KEY_EVENT_RECORD&)irec.Event).bKeyDown
- )//&& ! ((KEY_EVENT_RECORD&)irec.Event).wRepeatCount )
- {
- krec= (KEY_EVENT_RECORD&)irec.Event;
- return true;
- }
- }
- return false; //future ????
- }
- int main( )
- {
- KEY_EVENT_RECORD key;
- for( ; ; )
- {
- getconchar( key );
- std::cout << "key: " << key.uChar.AsciiChar
- << " code: " << key.wVirtualKeyCode << std::endl;
- if(key.wVirtualKeyCode==27) exit(0);
- }
- }
Add Comment
Please, Sign In to add comment