Anyone pls help me, i'm just learning C and my professor gave me a project. To make a simple Menu using only stdio.h, How do I input the Arrow Keys? Please Help
Anyone pls help me, i'm just learning C and my professor gave me a project. To make a simple Menu using only stdio.h, How do I input the Arrow Keys? Please Help
Are you sure they wanted you to make a menu you use arrows with?? Wouldn't a simple:
1. Option one
2. Option two
3. Option three
Choice>
Work?
My professor said I should use Arrow keys like this:
(The All Caps for example is the higlighted option)
OPTION1 option2 option3
when i press right option2 will be highlighted using cprintf and so on which ever choice i have selected till I press enter.
option1 OPTION2 option3
I think it has to do with ASCII codes or something
You could find the ascii value for the arrow keys, then have a variable for storing which one is highlighted (choice), and re-print the choices each time you push the arrow keys, with the right choice being highlighted.
with that as a small example. Then for choice==1 print "choice 1 CHOICE 2 choice 3" etc.Code:main { int choice=1, buff; printf("CHOICE 1 choice 2 choice 3"); for(buff=getch()!='ENTER') { if(buff=='LEFT ARROW') choice++ }
Draco, I sure hope that's pseudo code
>>for(buff=getch()!='ENTER')
eh?
Also, getch() is still non-standard C.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
yes, it is pseudo code. I'm a believer in tutoring others, not doing all the work for them.
Thanks for all the help:
Here's what i've done
Thanks again for all the helpCode:{ s1();d1();c=0; while(a!='\r') { a=getch(); if(a==77) /*ASCII code for right arrow*/ c++; if(a==75) /*ASCII code for left arrow*/ c--; if(c>3||c<-3) {c=0;} if(c==1||c==-3) {mc=2;s2();d2();} if(c==2||c==-2) {mc=3;s3();d3();} if(c==3||c==-1) {mc=4;s4();d4();} if(c==0) {mc=1;s1();d1();} } if(mc==1) {pro1();} if(mc==2) {pro2();} if(mc==3) {pro3();} if(mc==4) {pro4();} /*s1,s2,s3,s4 are functions that uses cprintf to display the selected menu */
Last edited by ghofigjong; 12-02-2002 at 04:37 PM.