Detecting multiple keypresses

Discussion in 'C Programming' started by kstahl, May 12, 2004.

  1. kstahl

    kstahl Guest

    Howdy,

    I would like to get down to the nitty-gritty of the keyboard's operation.
    Specifically, I would like to poll only a few keys on the keyboard, and I
    would like to know when more than one key is pressed. In other words, I
    would like to know how to access the keyboard's scan lines, so that if, for
    example, the user is holding two of the arrow keys pressed simultaneously, I
    will get a continuously changing response of Left-Right-Left-Right-and so
    on. So far, all that comes to mind is scanf(), but this is clearly
    inadequate.

    Thanks for your help,
    -Karl
    kstahl, May 12, 2004
    #1
    1. Advertising

  2. kstahl <> scribbled the following:
    > Howdy,


    > I would like to get down to the nitty-gritty of the keyboard's
    > operation.


    Can't be done in ISO standard C. Strictly speaking, you can't read the
    keyboard at all in ISO standard C, merely the standard input stream.
    Fortunately, most of the time there is a console handler reading the
    keyboard and feeding the characters to the standard input stream. How it
    does that is off-topic for comp.lang.c.

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "Remember: There are only three kinds of people - those who can count and those
    who can't."
    - Vampyra
    Joona I Palaste, May 12, 2004
    #2
    1. Advertising

  3. kstahl

    kstahl Guest

    Thanks for your prompt response. I'm not familiar with "console handlers" -
    can you recommend a newgroup/website where I might learn more about such
    topics?


    "Joona I Palaste" <> wrote in message
    news:c7tsvt$hd9$...
    > kstahl <> scribbled the following:
    > > Howdy,

    >
    > > I would like to get down to the nitty-gritty of the keyboard's
    > > operation.

    >
    > Can't be done in ISO standard C. Strictly speaking, you can't read the
    > keyboard at all in ISO standard C, merely the standard input stream.
    > Fortunately, most of the time there is a console handler reading the
    > keyboard and feeding the characters to the standard input stream. How it
    > does that is off-topic for comp.lang.c.
    >
    > --
    > /-- Joona Palaste () ------------- Finland --------\
    > \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    > "Remember: There are only three kinds of people - those who can count and

    those
    > who can't."
    > - Vampyra
    kstahl, May 12, 2004
    #3
  4. kstahl <> scribbled the following:
    > Thanks for your prompt response. I'm not familiar with "console handlers" -
    > can you recommend a newgroup/website where I might learn more about such
    > topics?


    It depends on what operating system you are using. Here are a few
    suggestions.
    For MS Windows: comp.os.ms-windows.programmer
    For Unix/Linux: comp.unix.programmer

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "To doo bee doo bee doo."
    - Frank Sinatra
    Joona I Palaste, May 12, 2004
    #4
  5. kstahl

    Neil Kurzman Guest

    oona I Palaste wrote:

    > kstahl <> scribbled the following:
    > > Howdy,

    >
    > > I would like to get down to the nitty-gritty of the keyboard's
    > > operation.

    >
    > Can't be done in ISO standard C. Strictly speaking, you can't read the
    > keyboard at all in ISO standard C, merely the standard input stream.
    > Fortunately, most of the time there is a console handler reading the
    > keyboard and feeding the characters to the standard input stream. How it
    > does that is off-topic for comp.lang.c.
    >
    > --
    > /-- Joona Palaste () ------------- Finland --------\
    > \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    > "Remember: There are only three kinds of people - those who can count and those
    > who can't."
    > - Vampyra


    With PC hardware it is not possible. getch() will give you a Key and scan code.
    There is no held down status.
    Neil Kurzman, May 13, 2004
    #5
  6. Neil Kurzman wrote:
    > oona I Palaste wrote:
    >
    >
    >>kstahl <> scribbled the following:
    >>
    >>>Howdy,

    >>
    >>>I would like to get down to the nitty-gritty of the keyboard's
    >>>operation.

    >>
    >>Can't be done in ISO standard C. Strictly speaking, you can't read the
    >>keyboard at all in ISO standard C, merely the standard input stream.
    >>Fortunately, most of the time there is a console handler reading the
    >>keyboard and feeding the characters to the standard input stream. How it
    >>does that is off-topic for comp.lang.c.
    >>
    >>--
    >>/-- Joona Palaste () ------------- Finland --------\
    >>\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    >>"Remember: There are only three kinds of people - those who can count and those
    >>who can't."
    >> - Vampyra

    >
    >
    > With PC hardware it is not possible. getch() will give you a Key and scan code.
    > There is no held down status.
    >
    >
    >


    Then how does Windows obtain the data for its key press messages?
    Last time I looked, the Windows operating system could differentiate
    between when a key was pressed and released.

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    Thomas Matthews, May 13, 2004
    #6
  7. kstahl

    Dan Pop Guest

    [OT] Re: Detecting multiple keypresses

    In <LXLoc.2401$> Thomas Matthews <> writes:

    >Then how does Windows obtain the data for its key press messages?
    >Last time I looked, the Windows operating system could differentiate
    >between when a key was pressed and released.


    IIRC (back in my MSDOS days I used to play with the keyboard interface of
    the PC, but it's been 15 years ago...) the keyboard is "seen" as an 8-bit
    port at some I/O address that "remembers" the last event received from
    the keyboard. 7 bits are used for the scan code and 1 bit to indicate
    whether the key was pressed or released.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, May 13, 2004
    #7
  8. kstahl

    Alan Balmer Guest

    On Thu, 13 May 2004 14:51:23 GMT, Thomas Matthews
    <> wrote:

    >
    >Then how does Windows obtain the data for its key press messages?
    >Last time I looked, the Windows operating system could differentiate
    >between when a key was pressed and released.
    >

    There are separate scan codes for key down and key up. However, it's
    *still* not topical here - take the discussion to some place like
    comp.os.ms-windows.programmer, where the answers will be more
    plentiful and more accurate.

    --
    Al Balmer
    Balmer Consulting
    Alan Balmer, May 13, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dag Sunde
    Replies:
    0
    Views:
    419
    Dag Sunde
    Dec 30, 2004
  2. bryan rasmussen
    Replies:
    2
    Views:
    357
    Jordan
    Oct 9, 2006
  3. Rich

    keypresses and signal handling

    Rich, Sep 25, 2010, in forum: C Programming
    Replies:
    29
    Views:
    1,301
    Ben Bacarisse
    Sep 27, 2010
  4. Myrddin Emrys
    Replies:
    1
    Views:
    130
    Daniel Martin
    Jul 24, 2006
  5. Replies:
    1
    Views:
    68
    Evertjan.
    Apr 14, 2007
Loading...

Share This Page