2

Pursuant to my earlier question, I'm trying to determine if I can read a byte without blocking.

Now, I've got several solutions that work for Unix-like systems, but they all crash and burn when trying to port it to windows, because it simply does not follow the unix "everything is a file" motto. On windows, there's no termios to flip the terminal into non-canonical mode, fstat doesn't tell you anything, and although WSA ostensibly offers select and more recently, poll, they only work on sockets, not any old file handle, and NOT the console "file".

So my only thought from checking through the MSDN is to get the count of input events, peek a copy and iterate through it, counting only KEY_UP typed events. But ... ick?! help? better way? or even a little less abominable?

Community
  • 1
  • 1
luser droog
  • 18,988
  • 3
  • 53
  • 105
  • 1
    No you can't do that on Windows with the Windows console. You might want to check [this Windows console function reference](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073%28v=vs.85%29.aspx). – Some programmer dude Aug 26 '14 at 12:55
  • I believe that the console input handle will be signaled if and only if there is at least one byte available via ReadFile/ReadConsole. You can test for this using WaitForSingleObject with a timeout of 0. – Harry Johnston Aug 26 '14 at 23:01
  • Thanks @HarryJohnston that's a good lead. [This doc](http://msdn.microsoft.com/en-us/library/ms687036(v=vs.85).aspx) says it should work for console input. – luser droog Aug 28 '14 at 08:07
  • @luserdroog: oh, that's where it is - I knew I'd seen it somewhere. Thanks. You'll only be able to read one byte per call, of course, but console input is slow anyway so the overhead shouldn't be a problem. – Harry Johnston Aug 28 '14 at 08:16
  • Possible answer http://stackoverflow.com/a/6419955/733077 – luser droog Feb 18 '16 at 22:01

0 Answers0