• Advertisement
Sign in to follow this  

knowing when a keyboard button had been pressed!

This topic is 2773 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

pretty much im wondering how to check each time a keyboard key is pressed....everytime a key is pressed i want my counter to add one to it...i can do the simple c++ stuff just not sure how/which API functions to use to be able to do this? any help would be greatful!

Share this post


Link to post
Share on other sites
Advertisement
Moved to For Beginners.

Share this post


Link to post
Share on other sites
Quote:
Originally posted on C++ Faq lite 15.17
[15.17] How can I tell {if a key, which key} was pressed before the user presses the ENTER key?

This is not a standard C++ feature — C++ doesn't even require your system to have a keyboard!. That means every operating system and vendor does it somewhat differently.

Please read the documentation that came with your compiler for details on your particular installation.


If you're using windows, then you can find this information here.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anri
For C++ and Windows, I just use DirectInput.
That is pretty much the last thing you should use, if you can help it. There may be some scenarios with valid reasons to use DirectInput, but getting keypresses is not one of them. For this particular case, DirectInput is the Devil.

Apart from minor technical reasons why one shouldn't use DirectInput, such as efficiency and being deprecated, the biggest issue with DirectInput (or raw input, which DirectInput wraps around) is that it does not respect user interface settings and localized hardware (keyboards) in the way window messages do.
Window messages will make sure that "things look right" and "things feel right", and that the right characters come out according to the keys you press. DirectInput does no such thing.

Failure to understand how to read and translate keys properly (or simply not caring?) has lead to a lot of software, even today, which is unusable to anyone not sitting in front of an en-US keyboard.

You would not believe how many programmers just don't get it that using DirectInput and hardcoding the scancodes for +, -, [ and ] for navigation is a devastating idea.
To begin with, the keys that the user has to press are not labelled correctly, but what's worse, some of them may not exist at all (or may require a modifier key).

It is already annoying if people don't get it that there are QWERTY and QWERTZ keyboards (and in reality, there are a lot more variations!), so the user has to press Z to get Y.
However, when it comes to figuring out where to find [ or /, you really lose all fun. This is usually the moment when the user starts shouting and wishes that the programmer dies from some nasty, painful disease.

To understand, imagine someone required you to use §, ß, and é for navigation on a en-US keyboard.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement