i need some help with a program,in which using a key press-n-hold (or simply hold),we can continue to execute any function till it is held or some other key is held to execute some different function.i tried making a program for such a purpose,but it has a glitch. let's consider as follows:
key hold 'i' is used for executing a function A, and key hold 'k' is used for executing function B. on key holding 'i' , function A gets executed repeatedly.now while key 'i' is held, key 'k' is also held,so execution switches over to function B. here both keys 'i' and 'k' are held now. when key 'k' is left while 'i' still held pressed, the execution does not shift back to function A, which is expected from the program. is there any solution to it?
the code is as follows:
Code:#include<stdio.h> #include<conio.h> void main() { int ch; clrscr(); while(1) { if (kbhit()) { ch=getch(); } else { ch=0; } delay(35); switch(ch) { case 105: printf("i"); break; case 107: printf("r"); break; case 27: exit(1); } } }