keyboard input question

hello everyone i am pretty new to C++ and have looked over many topics about this but cant seem to grasp it

what i want to know is how can i have it to where if i press a certain key on my
keyboard something happens

Example: if i press 'F'
cout << "you pressed F";

or if im creating a game pressing 'A' would move my character left...

any help would be nice

Last edited on
Windows provides many functions to make using the keyboard easy. If you are using another operating system, I'm sure they would provide an equally easy way to utilize the keyboard.
http://msdn.microsoft.com/en-us/library/ff468859%28v=VS.85%29.aspx Contains the full list of all functions,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <windows.h>

int main()
{
 	while (1)
	{
		for(int counter = 8; counter <= 190; counter++)
	    {
          if (GetAsyncKeyState(counter) == -32767)
          {
			  std::cout << char(counter) << '\t' << int(counter) << std::endl;
          }

	    }
	}
}


But if you are making a game, you should look into http://sfml-dev.org/ it provides a nice interface for using the keyboard, across platforms, as well as a lot of other needed functions for game development.
Topic archived. No new replies allowed.