When you use getch() what are the chars for the errors?
EDIT: I'm using C++, MSVS
Printable View
When you use getch() what are the chars for the errors?
EDIT: I'm using C++, MSVS
bump
I think you need to rephrase that question.
took me a long time to make this...
how would you use this?
Would you just compare the int returned with the value provided?
Does it work with getche()?
I am using DEV, if that effects it.
Code:<headers...>
#include "keys.h"
int main()
{
int keys;
keys=my_getch();
if (keys==K_LEFT)
{
printf("left key was pressed");
}
system("PAUSE");
return 0;
}
int my_getch ()
{
int input=getch();
if (input==224)
input=getch();
else if (input==0)
input=256+getch();
return input;
}
btw its been a lil while since i last programmed so there might be a small mistake :D havn't compiled yet should work with dev-c++ (waht i use)
Btw, look up the function kbhit()...Code:#include <iostream>
#include <stdlib.h>
#include "keys.h"
#include <conio.h>
using namespace std;
int move = 0;
char key;
int x = 0;
int y = 0;
int main()
{
do
{
key = getche();
move = (char)key;
if(move == K_UP)
y--;
else if(move == K_DOWN)
y++;
else if(move == K_LEFT)
x--;
else if(move == K_RIGHT)
x++;
}while(move != K_ESC);
system("PAUSE");
return 0;
}
EDIT: It looks like I took way too long on that post before red_baron beat me out.
red_baron, TechWin... that will not work in a Win32 console... well, it will compile; But it will not work properly.
You need to use virtual keys...
http://cboard.cprogramming.com/showt...threadid=25835
I was doing that for Inquirer; for some reason I was thinking he wanted it in console for Dev.
No one answered GreenCherry :D
I'm guessing NULL will indicate an error with getch();
NULL = 0