Thread: Key presses

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    180

    Key presses

    How do I code for a key press? Where does the code go?

    Thx for the help!

    DW

  2. #2
    Registered User
    Join Date
    Feb 2004
    Posts
    127
    sorry .. i didnt get you what do you mean by key press?

    is it in cosole programming??

    if you mean to press input you can use getch() ... i hope that you mean

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    ...depends on your platform / compiler.

    There is no standard way to do this. See the Programming FAQ. The C++ language standard expects you to type something in, and then hit ENTER. A standard-compliant program can work with a system that doesn't transfer data until ENTER is pressed.

    My compiler (Microsoft) includes kbhit() (keyboard hit). I think it's in <conio>. kbhit() returns zero if a key has not been pressed (or if the keyboard buffer is empty). It returns non-zero if a key has been pressed. So, you usually use it in a loop with an if-statement: if(kbhit() )... or, if(!(kbhit() ));
    Last edited by DougDbug; 03-23-2004 at 06:45 PM.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Ah, sorry. Not in a console app. In a windows app.

    Borland c++ builder 6

    cheers

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Ummm... I think you need a Windows book. I don't have it with me, but the standard book is Programming Windows, by Charles Petzold. I also don't remember the exact function(s). But, the code goes in your main Windows Processing Loop. When you press a key, move or ckick your mouse, the operating system sends a message to your program. You can capture or ignore these messages.

    II've never used Borlad Builder, but I'm sure it has an "easy" way of generating the code for processing keystrokes. Every Windows program has to do it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  3. Directional Keys - Useing in Console
    By RoD in forum C++ Programming
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM
  4. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM