detect what button they push without enter

This is a discussion on detect what button they push without enter within the C++ Programming forums, part of the General Programming Boards category; how can i do it, like how can i have it so it knows if have pushed like the right ...

  1. #1
    PHP
    PHP is offline
    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
    RoD
    RoD is offline
    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,796
    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
    PHP
    PHP is offline
    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, 01: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21