Borland C++ 5.0 input using arrow keys

  • C/C++
  • Thread starter Ephysics
  • Start date
  • Tags
    C++ Input
In summary, the conversation is about learning how to detect the user's input of arrow keys in Borland C++ 5.0. The user is looking for a tutorial on how to do this and someone suggests using kbhit or conio. The conversation also includes a code example for detecting arrow keys on Windows using getch and adding 256 to distinguish them from normal ASCII codes.
  • #1
Ephysics
3
0
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;
}
 
Technology news on Phys.org
  • #2
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
 
  • #3
mgb_phys said:
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

I am sorry, I don't understand what you are saying.
Ephysics
 
  • #4
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;
}
 

What is "Borland C++ 5.0 input using arrow keys"?

"Borland C++ 5.0 input using arrow keys" refers to the process of using arrow keys (up, down, left, right) to navigate and input data in a program written in Borland C++ version 5.0.

Why is input using arrow keys useful in Borland C++ 5.0?

Input using arrow keys allows for more precise and efficient data entry, especially when dealing with large amounts of data. It also provides a more user-friendly experience for the person using the program.

How do I enable arrow key input in Borland C++ 5.0?

To enable arrow key input in Borland C++ 5.0, you need to use the getch() function from the conio.h library. This function allows you to read input from the keyboard, including arrow keys.

Can I customize the functionality of arrow keys in my program?

Yes, you can customize the functionality of arrow keys in your program by using conditional statements to determine the action to be taken when a certain arrow key is pressed. This allows for more flexibility and control over the input process.

Are there any limitations or considerations when using arrow key input in Borland C++ 5.0?

One limitation to keep in mind is that arrow key input may not be supported on all systems or in all versions of Borland C++. It is important to test your program on different systems to ensure compatibility. Additionally, it is important to handle any unexpected inputs or errors that may occur when using arrow keys.

Similar threads

  • Programming and Computer Science
Replies
5
Views
2K
Replies
7
Views
4K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
5
Views
8K
  • Programming and Computer Science
Replies
33
Views
6K
  • Programming and Computer Science
Replies
4
Views
2K
Replies
15
Views
4K
  • Computing and Technology
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Programming and Computer Science
Replies
2
Views
3K
Back
Top