5

Is there some Linux analog of windows function GetAsyncKeyState() ? Or maybe there exists some asynchronous function which returns - Does keyboard buffer empty or not ?

Thanks.

Björn Lindqvist
  • 16,492
  • 13
  • 70
  • 103
Agnius Vasiliauskas
  • 10,413
  • 5
  • 46
  • 66

1 Answers1

5

The key question here is: For which abstraction? X windows, ncurses or stdio? Linux isn't as simple and monolithic as Windows is.

For stdio (plain old stdin/stdout text program) fgetc_unlocked does the trick.

thiton
  • 34,333
  • 3
  • 63
  • 96
  • 3
    `Linux isn't as simple and monolithic as Windows is.`. This is a gratuitous affirmation. – user703016 Oct 04 '11 at 08:33
  • 1
    "Linux isn't as simple and monolithic as Windows is" is an absolutely spot-on comment in the context of this question. +1 – David Heffernan Oct 04 '11 at 08:37
  • 2
    @Cicada: It is a quite simplifying affirmation, but the OP needs to get on the right track: If you are asking "Is the Y key held down?" on a UNIX system, a UNIX system with the right error codes would answer with EWHICHONE: "*Which* Y key? I'm potentially serving hundreds of users distributed over a whole planet, and half of them are probably using Braille readers or okuleles for input." – thiton Oct 04 '11 at 08:42
  • Just for information: Linux uses a monolithic approach with its kernel, instead of Windows that uses a micro-kernel approach. Just for educational purposes. I hate Winzozz, and i'm a Unix fan and user with both Linux, Solaris and OSX. :) – Martino Lessio Jan 11 '13 at 17:07