C++ question

i got a question...i want to use the keyboard in my c++ codes ex..if u press UPARROW key something happens.... EX:
1
2
3
4
if(uparrowkey== pressed)
{
cout<<" this means nothing thats just an example of wot i want :D "<<endl;
}
Well im sorry but i looked there :P! didnt help me =/... i also googled it but still cant find the correct answer .... :(
1
2
3
4
5
6
7
8
9
10
11
12
#include <conio.h>
#include <iostream>

int main()
{
	unsigned char LOL;
	while(1){
	LOL = getch();
	std::cout << (int)LOL << ' ' << LOL << '\n';
	}
	return 0;
}


As you can see by using this code, an arrow returns a specific value. You can store that value in an integer variable, and then compere that value in de condition of an if-statement
hehe i know it returnedd that... well give it in an example of if statement... :D
ex of wot i want
1
2
3
4
5
6
7
8
9
10
11
#include<iostream>
using namespace std;
int main()
{
if (KEY==pressed) 
{
cout<<"hello"<<endl;
}
cin.get();
return 0;
}
Last edited on
" As you can see by using this code, an arrow returns a specific value. You can store that value in an integer variable, and then compere that value in de condition of an if-statement "


how?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <conio.h>
#include <iostream>

int main()
{
	int input;
	while(1){
    input= getch();
	std::cout << input << "\n";
	if (input==72)
	std::cout<<"Up!\n";
	if (input==75)
	std::cout<<"Left!\n";
	if (input==77)
	std::cout<<"Right!\n";
	if (input==80)
	std::cout<<"Down!\n";
    }
    return 0;
}

I dont know or there is a way to do this as you're trying. You should searce the reference-part of this website for that.
Last edited on
I OWE U ALOT! max thx =] =] :)
by the way where did u find those numbers??? (ex:72 is up , 75 is left , 77 is right , 80 is down :S )??
By using the first code :)

(If you try it, you will see that 'up' not only returns 72, but also 224 and, depending of the kind of datatype you are storing the value in, a letter)
Thanks :)... for ur replies and helpfull advices :)
Topic archived. No new replies allowed.