Detecting multiple keypresses

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kstahl

    #1

    Detecting multiple keypresses

    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


  • Joona I Palaste

    #2
    Re: Detecting multiple keypresses

    kstahl <kstahl@stanfor d.edu> scribbled the following:[color=blue]
    > Howdy,[/color]
    [color=blue]
    > I would like to get down to the nitty-gritty of the keyboard's
    > operation.[/color]

    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 (palaste@cc.hel sinki.fi) ------------- 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

    Comment

    • kstahl

      #3
      Re: Detecting multiple keypresses

      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" <palaste@cc.hel sinki.fi> wrote in message
      news:c7tsvt$hd9 $1@oravannahka. helsinki.fi...[color=blue]
      > kstahl <kstahl@stanfor d.edu> scribbled the following:[color=green]
      > > Howdy,[/color]
      >[color=green]
      > > I would like to get down to the nitty-gritty of the keyboard's
      > > operation.[/color]
      >
      > 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 (palaste@cc.hel sinki.fi) ------------- Finland --------\
      > \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
      > "Remember: There are only three kinds of people - those who can count and[/color]
      those[color=blue]
      > who can't."
      > - Vampyra[/color]


      Comment

      • Joona I Palaste

        #4
        Re: Detecting multiple keypresses

        kstahl <kstahl@stanfor d.edu> scribbled the following:[color=blue]
        > 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?[/color]

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

        --
        /-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
        \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
        "To doo bee doo bee doo."
        - Frank Sinatra

        Comment

        • Neil Kurzman

          #5
          Re: Detecting multiple keypresses

          oona I Palaste wrote:
          [color=blue]
          > kstahl <kstahl@stanfor d.edu> scribbled the following:[color=green]
          > > Howdy,[/color]
          >[color=green]
          > > I would like to get down to the nitty-gritty of the keyboard's
          > > operation.[/color]
          >
          > 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 (palaste@cc.hel sinki.fi) ------------- 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[/color]

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



          Comment

          • Thomas Matthews

            #6
            Re: Detecting multiple keypresses

            Neil Kurzman wrote:[color=blue]
            > oona I Palaste wrote:
            >
            >[color=green]
            >>kstahl <kstahl@stanfor d.edu> scribbled the following:
            >>[color=darkred]
            >>>Howdy,[/color]
            >>[color=darkred]
            >>>I would like to get down to the nitty-gritty of the keyboard's
            >>>operation.[/color]
            >>
            >>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 (palaste@cc.hel sinki.fi) ------------- 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[/color]
            >
            >
            > With PC hardware it is not possible. getch() will give you a Key and scan code.
            > There is no held down status.
            >
            >
            >[/color]

            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:

            C++ Faq: http://www.parashift.com/c++-faq-lite
            C Faq: http://www.eskimo.com/~scs/c-faq/top.html
            alt.comp.lang.l earn.c-c++ faq:

            Other sites:
            http://www.josuttis.com -- C++ STL Library book

            Comment

            • Dan Pop

              #7
              [OT] Re: Detecting multiple keypresses

              In <LXLoc.2401$kM5 .1192@newssvr16 .news.prodigy.c om> Thomas Matthews <Thomas_Matthew sSpitsOnSpamBot s@sbcglobal.net > writes:
              [color=blue]
              >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.[/color]

              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@ifh.de

              Comment

              • Alan Balmer

                #8
                Re: Detecting multiple keypresses

                On Thu, 13 May 2004 14:51:23 GMT, Thomas Matthews
                <Thomas_Matthew sSpitsOnSpamBot s@sbcglobal.net > wrote:
                [color=blue]
                >
                >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.
                >[/color]
                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.program mer, where the answers will be more
                plentiful and more accurate.

                --
                Al Balmer
                Balmer Consulting
                removebalmercon sultingthis@att .net

                Comment

                Working...