-1

I'm trying to write a Keyboard class that can read in the keyboard buttons. I have looked at this link - http://www.daniweb.com/software-development/cpp/code/216732/reading-scan-codes-from-the-keyboard But as stated on there, it is not very accurate for all computers (I don't know if this is even true). Therefore, my question is whats the best method in implementing my keyboard class? This will be used for Windows

Many thanks

Danny
  • 9,199
  • 16
  • 53
  • 75
  • THere's far too little information in this question to provide a meaningful answer. What hardware, which OS? These would be starting points. – marko Mar 07 '13 at 18:04
  • See these questions: http://stackoverflow.com/questions/8792317/why-cant-i-find-conio-h-on-linux and http://stackoverflow.com/questions/3276546/how-to-implement-getch-function-of-c-in-linux. – TAS Mar 07 '13 at 19:14

1 Answers1

0

There are three ways to read keyboard input:

  1. By reading input from a console window as described in your link. It's true that it's hard to get this to work correctly, for starters because it's reading ANSI characters and not Unicode characters, but there are other issues. Console input/output is kind of obscure, as is the documentation for it
  2. By handling UI events associated with a normal window. In this case you would handle the WM_KEYDOWN message in a window procedure
  3. By going deep into the Win32 API with functions like SetWindowsHookEx. In this case you don't even need a window (normal or console), and you can read keystrokes pressed in any application or in the desktop

It's hard to suggest which one to use without knowing how you intend to use this Keyboard class.

user1610015
  • 6,561
  • 2
  • 15
  • 18