c++ how to detect Enter button input

Started by
9 comments, last by Servant of the Lord 9 years, 2 months ago
i have been trying to detect enter button and arrow keys and failing realy hard if some one could give me a source to detect arrow and enter key i would be realy greatful
Advertisement

Which operating system are you using, and which programming language?

There is no C++ way to do this. The language does not assume it is compiling programs for use on a device with a keyboard.

Such things are handled via libraries for the operating system you are running on.

However, if you mean in a console app, many compilers ship with a nonstandard header called conio.h or similar which provides something like kbhit(). It really depends on the context you need.
c++ on windows using codeblocks and mingw

Since you are on windows try looking at using the windows.h file and google GetAsyncKeyState should be all you need to figure it out.

c++ on windows using codeblocks and mingw


Console app or Windows app?

For console apps look up stdio.h, iostream, and friends.

For windowed apps, look up GetAsyncKeyState and WM_KEYDOWN/WM_KEYUP.

You probably want to abstract windowed mode input anyway as it a bit of a minefield to do properly. Search this forum for tons of advice using those keywords above...

Good luck!

Which API are you using? Did you succeed in getting SFML working?

By "button" do you mean a button widget in a window that the player clicks on with a mouse, or do you mean a keyboard key, or do you mean the left or right mouse buttons?

i mean keyboard button and im just using plain c++
and no i didnt get sfml to work i dont know what's the matter but ill try to post a picture

This topic is closed to new replies.

Advertisement