#include <stdlib.h>
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: \n");
ch = fgetc(stdin);
if(ch == 'A')
{
printf("A was inputed.\n");
}
else
{
printf("%c was inputed.\n", ch);
}
return 0;
}
So this is a simple program: When you input A and press enter, "A was inputed" gets printed. If you input any other character it will print " was inputed."
But I want to make it like this: When the right arrow key is pressed, it will print "Right Arrow Key", but when the left arrow key is pressed, it will print "Left Arrow Key".
How do I do this?
I can do this with the enter key by doing this.
if(ch == 0x0A)
{
printf("ENTER KEY was pressed\n");
}
else
{
}
I learned that 0x0A is the hexadecimal ASCII value of the enter key. So I thought I could do the same with other keys after I get their hexadecimal ASCII value. But I don't know the ones for the right arrow and left arrow keys.
EDIT: I should have mentioned that I use Windows 10.