KeyPress Event

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

    KeyPress Event

    I'm trying to capture when a user presses a particular key (escape), so
    I'm coding in the KeyPress event. Yet the code seems be bypassed
    (breakpoint is never encountered). Should I be coding in a different
    event? Is this a known issue? FYI, this is happening in both Access 97
    and 2000.

  • Peter Doering

    #2
    Re: KeyPress Event

    On Tue, 09 Sep 2003 17:20:52 GMT, William Ortenberg wrote:
    [color=blue]
    > I'm trying to capture when a user presses a particular key (escape), so
    > I'm coding in the KeyPress event. Yet the code seems be bypassed
    > (breakpoint is never encountered). Should I be coding in a different
    > event? Is this a known issue? FYI, this is happening in both Access 97
    > and 2000.[/color]

    You have to set "KeyPreview " = true.

    Also, you should know about the difference between KeyDown, KeyUp and
    KeyPress. See OH.

    HTH - Peter

    --
    No mails please.
    This posting is provided AS IS with no warranties, and confers no rights.

    Comment

    • Marc

      #3
      Re: KeyPress Event

      William Ortenberg <billort@pacbel l.net> wrote in message news:<UZn7b.675 $sM.612@newssvr 29.news.prodigy .com>...[color=blue]
      > I'm trying to capture when a user presses a particular key (escape), so
      > I'm coding in the KeyPress event. Yet the code seems be bypassed
      > (breakpoint is never encountered). Should I be coding in a different
      > event? Is this a known issue? FYI, this is happening in both Access 97
      > and 2000.[/color]


      William,

      The keypress-event does only respond to ANSI-characters and not to
      non-text keys like escape, enter, cursor-keys, Home PgDn etc. The
      effect of the shift-keys result in another character if valid. The
      keyUp end KeyDown events however do respond to the escape-key and give
      back a numeric value for each physical key with some exeptions and
      conditions depending on the form-properties (see url

      etc)
      Other than fhe keypress-event they also return the state of the shift,
      control and alt-key states seperately.
      see also the useful article


      Marc

      Comment

      • Peter Doering

        #4
        Re: KeyPress Event

        > The keypress-event does only respond to ANSI-characters and not to[color=blue]
        > non-text keys like escape, enter, cursor-keys, Home PgDn etc. ...[/color]

        Try this:

        Key Preview=Yes

        Private Sub Form_KeyPress(K eyAscii As Integer)
        If KeyAscii = vbKeyEscape Then
        MsgBox "ESC pressed."
        End If
        End Sub


        Peter

        --
        No mails please.
        This posting is provided AS IS with no warranties, and confers no rights.

        Comment

        • Michael \(michka\) Kaplan [MS]

          #5
          Re: KeyPress Event

          This is not correct. You should use the KeyDown event for this, not
          KeyPress.


          --
          MichKa [MS]

          This posting is provided "AS IS" with
          no warranties, and confers no rights.


          "Peter Doering" <news@doering.o rg> wrote in message
          news:bjml2m$k4l 2l$1@ID-204768.news.uni-berlin.de...[color=blue][color=green]
          > > The keypress-event does only respond to ANSI-characters and not to
          > > non-text keys like escape, enter, cursor-keys, Home PgDn etc. ...[/color]
          >
          > Try this:
          >
          > Key Preview=Yes
          >
          > Private Sub Form_KeyPress(K eyAscii As Integer)
          > If KeyAscii = vbKeyEscape Then
          > MsgBox "ESC pressed."
          > End If
          > End Sub
          >
          >
          > Peter
          >
          > --
          > No mails please.
          > This posting is provided AS IS with no warranties, and confers no rights.[/color]


          Comment

          • Peter Doering

            #6
            Re: KeyPress Event

            > This is not correct. You should use the KeyDown event for this, not[color=blue]
            > KeyPress.[/color]

            I know!

            The statement was that KeyPress won't respond to ESC, but it does. I've
            tested it.

            Peter

            Comment

            • Michael \(michka\) Kaplan [MS]

              #7
              Re: KeyPress Event

              The point is that it is foolish to rely on it, since apps will often trap
              and remove the keystroke before it ever makes it to a WM_CHAR message (the
              basis of the KeyPress event). Reliable code is always better....


              --
              MichKa [MS]

              This posting is provided "AS IS" with
              no warranties, and confers no rights.


              "Peter Doering" <news@doering.o rg> wrote in message
              news:bjnc1c$l2q gq$1@ID-204768.news.uni-berlin.de...[color=blue][color=green]
              > > This is not correct. You should use the KeyDown event for this, not
              > > KeyPress.[/color]
              >
              > I know!
              >
              > The statement was that KeyPress won't respond to ESC, but it does. I've
              > tested it.
              >
              > Peter[/color]


              Comment

              • Peter Doering

                #8
                Re: KeyPress Event

                > The point is that it is foolish to rely on it, since apps will often trap[color=blue]
                > and remove the keystroke before it ever makes it to a WM_CHAR message (the
                > basis of the KeyPress event). Reliable code is always better....[/color]

                Thanks. For common people who rely on OH this is not really obvious. Is
                there a place where one can read about it?

                When would you use KeyPress or KeyUp?

                Peter

                --
                No mails please.

                Comment

                • Michael \(michka\) Kaplan [MS]

                  #9
                  Re: KeyPress Event

                  KeyDown and KeyUp are responding to WM_KEYDOWN and WM_KEYUP messages, and
                  KepPress resonds to a WM_CHAR message. The first to respond to physical
                  keystroke push/release, while the latter responds to when a message loop
                  asks Windows to translate that keystroke to a character.


                  --
                  MichKa [MS]

                  This posting is provided "AS IS" with
                  no warranties, and confers no rights.


                  "Peter Doering" <news@doering.o rg> wrote in message
                  news:bjrvlq$m6d ff$1@ID-204768.news.uni-berlin.de...[color=blue][color=green]
                  > > The point is that it is foolish to rely on it, since apps will often[/color][/color]
                  trap[color=blue][color=green]
                  > > and remove the keystroke before it ever makes it to a WM_CHAR message[/color][/color]
                  (the[color=blue][color=green]
                  > > basis of the KeyPress event). Reliable code is always better....[/color]
                  >
                  > Thanks. For common people who rely on OH this is not really obvious. Is
                  > there a place where one can read about it?
                  >
                  > When would you use KeyPress or KeyUp?
                  >
                  > Peter
                  >
                  > --
                  > No mails please.[/color]


                  Comment

                  Working...