| Thread Closed |
Borland C++ 5.0 input using arrow keys |
Share Thread | Thread Tools |
| May29-09, 11:38 AM | #1 |
|
|
Borland C++ 5.0 input using arrow keys
hi!
I've started making my own games in Borland C++ 5.0 I want to learn how to detect the user's input of arrow keys (for eg. when a user presses UP,DOWN ,RIGHT or LEFT) Can somebody please post a short tutorial on detecting arrow keys? Thank You Ephysics PS- Is this correct ? int c = getch(); if(c == 0) { c = getch(); c*=256; } |
| May29-09, 12:14 PM | #2 |
|
Recognitions:
|
You can't use getch with special keys.
The lib for your compiler needs to have an OS specific function, it's also different if you are in windows or on a console. Look for something like kbhit or conio |
| May30-09, 01:06 AM | #3 |
|
|
Ephysics |
| May30-09, 04:21 PM | #4 |
|
|
Borland C++ 5.0 input using arrow keys
On Windows, the special keys form a chain of two characters, beginning with a zero. It is like another page of ASCII characters with an added value of 256.
The following example program compiled with Borland C++ should make this clear. Compile and run the following program, then you can check the codes required, for example, left/right/down/up arrows have codes 331,333,336,328 respectively with the added 256 to distinguish from the normal ASCII codes. To quit the program, press the escape key (ASCII 27 decimal, octal 33) Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main(int argc, char *argv[]){
unsigned car=' ';
do{
if(car==0)car=getch()+256;
printf("%ud",car);
}while((car=getch())!='\033');
return 0;
}
|
| Thread Closed |
| Thread Tools | |
Similar Threads for: Borland C++ 5.0 input using arrow keys
|
||||
| Thread | Forum | Replies | ||
| Dashed arrow and solid arrow in category theory | Linear & Abstract Algebra | 7 | ||
| Electrical and Computer Engineering, 2-input Look-Up tables designed with 2-input XOR | Engineering, Comp Sci, & Technology Homework | 0 | ||
| how to use borland C for drawing | Programming & Comp Sci | 1 | ||
| how to obtain 4 input or gate using 2 input gates? | Introductory Physics Homework | 3 | ||
| Logic question, 3 input OR to 2 input OR | Electrical Engineering | 9 | ||