What will getch() return for these keys:
Left Arrow
Right Arrow
Up Arrow
Down Arrow
ESC
F1-12
Tab
Enter
Shift
CTRL
ALT
Backspace
like in this
switch (getch())
{
case LEFT ARROW:
blah blah
break;
}
What will getch() return for these keys:
Left Arrow
Right Arrow
Up Arrow
Down Arrow
ESC
F1-12
Tab
Enter
Shift
CTRL
ALT
Backspace
like in this
switch (getch())
{
case LEFT ARROW:
blah blah
break;
}
Why don't you enter this in the compiler and check it for yourself:
Most if not all of those keys will cause the program to not display anything. This is because they do not have corresponding ASCII codes.Code:#include <iostream.h> #include <conio.h> int main() { char ch = getch(); cout << ch << endl; return 0; }
Of course, ya never know. A few might bring some unexpected results...
Up, down, left, and right arrow shows 0 in my ASCII codes...
Yoshi
Well, there ya have it.
up is 72,
down is 80,
right is 77,
left is 75
If this is what you're looking for, no thanx needed. if not, Then i don't know
Code:#if _emo #define stereo_type_i_dislike #endif
Okay, I got it to do letters. K = left H = up P = down M = right
Now when I press an arrow it returns zero the first time I press it, then it returns the letter. WTF? Why does it do this, and can I override it doing that? Or do I need to just tell the user to press left twice or down twice to move.
I think it has something to do with upper and lower bytes... Well, I don't know so I should probably just shut up .
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
hi
simply use this code:
x=getch();
if(x==0) // is special key else is normal key (a, b, RETURN, ESC ....)
y=getch(); // number of y is the key pressed (up, down, F1, F2...)
i hope this helps.
bye
PLEASE HELP ME WITH MY MOUSE IN 800x600 24 BIT MODE!!!
You can try this out if you like. A sort of in the works project.
#include <stdio.h>
#include <conio.h>
#define KEYBOARD 0x60
#define KCONTROL 0x61
#define KINTCONTROL 0x20
#define LARROW 75
#define RARROW 77
// continue from there
#define F_1 59
#define F_2 60
// continue from there
int key;
int getKey(void);
int main()
{
getKey();
switch(key)
{
case LARROW: printf("\nleft arrow key pressed.");
break;
case F_1: printf("\nF1 key pressed.");
break;
// and so on
}
return 0;
} // end main
int getKey(void)
{
printf("\nPress a key: ");
key = getch();
_asm
{
sti
in al,KEYBOARD
xor ah,ah
mov key,ax
in al,KCONTROL
or al,82h
out KCONTROL,al
and al,7fh
out KCONTROL,al
mov al,20h
out KINTCONTROL,al
}
return key;
}
I hope there are no typoes as this was rushed.
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P
thats okay, I'm just going to make it loop the getch() again if it's zero. That way it don't flash, because the character and the HP/MP flash everytime you take a step for some reason.
Ah, A RPG hound then? A 3D game?
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P
did this, it gets the arrow keys and does *something* depending on which arrow key. Pretty simple, should be easy to modify for your use.
//code:
void cursor()
{
// getch();
int c = 1;
int ch = 0;
while (ch != c)
{
ch = getch();
// cout << ch << endl;
if(ch == 72) // if UP
cout << "^" << endl;
if(ch == 80) // if Down
cout << "d" << endl;
if(ch == 75) // if left
cout << "<" << endl;
if(ch == 77) // if right;
cout << ">" << endl;
}
}
// ^^ end code!
c++->visualc++->directx->opengl->c++;
(it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)