Thread: Display message after key press?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    1

    How to properly display message after key press

    Hi,
    I need some helping hand.
    I have to display each message only once when a key is pressed.
    The problem in this code is that the message flickers/runs infinite loop.
    How should I go about making it run only once every key press?

    Thanks.

    Code:
    do { c = inportb(COM1 + 5);
    	if (c & 1) {char = inportb(COM1);
    		   
    		  if (char == 79) // if O press
    		  {	
                          clrscr();
    		      printf("Letter O");
    		   }
    		   else if (char == 88)            //if X press
    		   {
                          clrscr();
    		      printf("Letter X");
    		   }
    		   else if (char == 89)          //if Y press
    		   {
    		      printf("Letter Y");
    		      clrscr();
    		   }
    		   else if (char == 90)         //if Z press
    		   {
                          clrscr();
    		      printf("Letter Z");
    		   }
    	if (kbhit()){char = getch();	//if key pressed, get char
    		    outportb(COM1, char);}	//send char to serial port
    	} while (char !=27);	// if ESC pressed exit
      }
    Last edited by mike77; 04-06-2007 at 02:26 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. Window message loop (Keys)
    By Blackroot in forum Windows Programming
    Replies: 3
    Last Post: 09-12-2006, 05:15 PM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. How to put a press any key function?
    By Manish Shrestha in forum C++ Programming
    Replies: 6
    Last Post: 03-23-2002, 05:26 PM
  5. Pause or press any key to continue
    By muffin in forum C Programming
    Replies: 3
    Last Post: 09-12-2001, 12:26 PM