0
#include <stdio.h>
#include <conio.h>


int main() {
    int ch = getch();
   // printf ("%d" , ch);
    switch (ch){
        case 13:
            printf("ENTER");
           break;
        case 224:
            printf("LEFT ARROW");
            break;
        case  45 :
            printf("LOWERCASE LETTER");
            break;
        case  27 :
            printf("ESC");
             break;
        case  48 :
            printf ("digit");
            break;
        case 49   :
            printf("digit");
             break;
        case 50  :
            printf("digit");
             break; 
        case  51  :
            printf("digit");
             break;
        case   52 :
            printf("digit");
             break; 
        case  53  :
            printf("digit");
             break;
        case  54  :
            printf("digit");
             break;     
        case   55 :
            printf("digit");
             break;
        case 56  :
            printf("digit");
             break; 
        case 57 :
            printf("digit");
             break;
        
        
    }
    
}

I am trying to label different keyboard inputs but I was not able to label different f key pressings as well as arrow keys since it returns the same int value. How can I label different F key pressings

This is a filler line to bypass stackoverflows unnecessary filters

Geliebten
  • 9
  • 3
  • 2
    From what I remember from the dinosaur age, the arrow keys returned 2 bytes, not 1. You'd get the code followed by a zero byte iirc. Any particular reason why you are training to become a MS DOS programmer though? – Lundin Oct 29 '21 at 11:26
  • It may even be 4 bytes on macos... – mmeisson Oct 29 '21 at 11:30
  • I don't have much experience with programming so could you please elaborate more how could I approach this problem? – Geliebten Oct 29 '21 at 11:33
  • 1
    What do you mean by "_This is a filler line to bypass stackoverflows unnecessary filters_"? – the busybee Oct 29 '21 at 11:39

1 Answers1

0

I think you can get a lot of information at "getch and arrow codes" .

Like @Lundin said, the arrow keys returned value is not 1, so you should know which key echoes how many bytes, and then you can design your judgment.

I suggest you can understand the principle of your code first, and search the answer by keyword on the GOOGLE (EX: conio.h, getch()...etc).

If still has problems, you post here, I think everyone will kindly answer for you.

jackieBB
  • 126
  • 1
  • 2
  • 3