Results 1 to 3 of 3

Thread: How do i check to see if a key is being pressed?

  1. #1
    Guest

    Post

    How do i check to see if a key is being pressed while in a "while()" loop?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If you're in a Windows app - your window will receive a WM_CHAR message.

    For console apps, try the getch() function. Unfortunately I think that doesn't return until a key is pressed...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guest
    Use the _getch function.
    Code:
    #include <conio.h>
    #include <ctype.h>
    
    void main()
    {
       char ch;
    
       _cputs( "Enter a letter: " );
       // Loop until "Y" is pressed
       do
       {
          ch = _getch();
          ch = toupper( ch );
       } 
       while( ch != 'Y');
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width