C++ console keyboard events

前端 未结 5 1377
南笙
南笙 2020-11-30 14:57

Is there any way to get key events in a Windows console? I need a way to get keydown and keyup events quickly without a GUI. I\'ve tried using getch(), but it doesn\'t get k

5条回答
  •  醉话见心
    2020-11-30 15:34

    Use ReadConsoleInput() API. Watch for events of kind KEY_EVENT. This won't work for all keydown events (Ctrl-key, shift-key, Pause-key cannot be read), but most can be read.

    Use GetNumberOfConsoleInputEvents to avoid blocking.

提交回复
热议问题