Enter C ++ key in Windows console

I am currently developing various console games on Windows that will not work using normal cin input.

How can I (in a simple way use only the standard Windows libraries available in MSVC):

  • Make the program wait for the key to be pressed (specific?) And return the key identifier (it should work for all keys, including arrow keys)

  • During the game in real time, check the last key pressed by the user and if any key has been pressed since the last check.

It would really help if you could include a short sample program for your solution.

+4
source share
3 answers

AFAIK, you cannot do this using standard C runtime. You will need to use something like the Win32 GetAsyncKeyState function.

+1
source

You need a Windows console API like PeekConsoleInput .

+1
source

I have only what you need.

I like a buddy here: C ++ source

This is pretty clear, but if you have any doubts, my email address is jacobossm@gmail.com

+1
source

Source: https://habr.com/ru/post/1301027/


All Articles