C language console read up and DOWN ARROW key instructions

Source: Internet
Author: User

First, you can detect any keystroke key value

#include <stdio.h>#include<conio.h>int  main () {           char  ch;      while ((Ch=getch ())! =0x1B/**/{   printf ("% d \ n"

is the key value of the next key or lower.

Second, the console reads the direction key directive

Method One

//capturing key Values#include <stdio.h>#include<conio.h>intMain () {intch;  while((Ch=getch ())! =0x1B)/*Press ESC to quit ...*/   {      Switch(CH) { Case 0xE0:         Switch(ch=Getch ()) {             Case  the: printf ("up\n"); Break;  Case  the: printf ("down\n"); Break;  Case  the: printf ("left\n"); Break;  Case  the: printf ("right\n"); Break; default:                Break; }          Break; default:          Break; }   }}

Method Two

#include <stdio.h>#include<stdlib.h>#include<conio.h>#include<windows.h>intMain () {Charkey;  while(1)    {        //int t=1;key=Getch (); Switch(key) { Case- +: Key=Getch (); Switch(key) { Case  the: printf ("up\n"); Break;  Case  the: printf ("down\n"); Break;  Case  the: printf ("left\n"); Break;  Case  the: printf ("right\n"); Break;  Case-123: printf ("f11\n"); Break;  Case-122: printf ("f12\n"); Break; default:            //printf ("%x,%d,%c\n", t,t,t);printf"NULL"); Break; }             Break; default:            //printf ("%x,%d,%c\n", t,t,t);printf"NULL"); Break; }    }    return 0;}

C language console read up and DOWN ARROW key instructions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.