Thread: detect what button they push without enter

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    41

    detect what button they push without enter

    how can i do it, like how can i have it so it knows if have pushed like the right arrow instead of having them type r and enter it...
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    getch() or virtual keys, read the FAQ.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Here's a windows method that's relatively simple:
    Code:
    #include <iostream>
    #include <climits>
    #include <windows.h>
    
    int main()
    {
      short esc = 0;
    
      while ( !esc ) {
        esc = GetAsyncKeyState ( VK_ESCAPE );
    
        if ( GetAsyncKeyState ( VK_UP ) & SHRT_MAX )
          std::cout<<"Up arrow is pressed\n";
        else if ( GetAsyncKeyState ( VK_DOWN ) & SHRT_MAX )
          std::cout<<"Down arrow is pressed\n";
        else if ( GetAsyncKeyState ( VK_LEFT ) & SHRT_MAX )
          std::cout<<"Left arrow is pressed\n";
        else if ( GetAsyncKeyState ( VK_RIGHT ) & SHRT_MAX )
          std::cout<<"Right arrow is pressed\n";
    
        std::cout.flush();
      }
    
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    41
    thanx prelude, thats exactly what i need
    In order of learned:
    HTML - Mastered
    CSS - Enough to use
    SSI - Mastered
    PHP - Advanced
    C/C++ - Current Project

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting position from game..
    By brietje698 in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2007, 12:15 PM
  2. Queues
    By ramayana in forum C Programming
    Replies: 22
    Last Post: 01-01-2006, 02:08 AM
  3. Don't push that button!
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-17-2003, 08:37 PM
  4. terminate 0 - PLEASE HELP
    By Unregistered in forum C Programming
    Replies: 11
    Last Post: 11-21-2001, 07:30 AM
  5. Desperate for help - ugly nested if
    By baseballkitten in forum C Programming
    Replies: 4
    Last Post: 11-19-2001, 03:56 PM