Thread: several key pressed

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    several key pressed

    if more than one key is down at the same time, how do you get both of them?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    depends on the operating system. MS-Windows: there is a WM_KEYDOWN message sent each time a key is pressed and WM_KEYUP when the key is released. shift, control and alt keys do not generate those events.

    if you are using standard functions from stdio.h then just keep caling getch() until no more keys. How to tell when no more keys? There is no standard way to do that. If you compiler supports conio.h you might be able to use _kbhit() which returns 0 when nothing in the keyboard buffer.

    Or you can use fgets() which will put everything up to the <Enter> into your buffer. Then you can check that buffer for each key.
    Last edited by Ancient Dragon; 12-22-2005 at 10:32 AM.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    if you are using standard functions from stdio.h then just keep caling getch() until no more keys. How to tell when no more keys? There is no standard way to do that. If you compiler supports conio.h you might be able to use _kbhit() which returns 0 when nothing in the keyboard buffer.
    getch() isn't standard, and besides, it's in <conio.h>. If you have getch(), you likely have kbhit() or _kbhit() too.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 11:29 AM
  3. Function to check memory left from malloc and free?
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 05:45 AM
  4. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM