Arrow Keys

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

    #1

    Arrow Keys

    How can you detect when an arrow key gets pressed? Doesn't seem to trigger
    a KeyPress or KeyDown event. Thanks.

    Jerry


  • AMercer

    #2
    RE: Arrow Keys

    use the KeyDown event.

    "Rlrcstr" wrote:
    [color=blue]
    > How can you detect when an arrow key gets pressed? Doesn't seem to trigger
    > a KeyPress or KeyDown event. Thanks.
    >
    > Jerry
    >
    >
    >[/color]

    Comment

    • AMercer

      #3
      RE: Arrow Keys

      sorry - posted too soon ... use the KeyDown event. check for keys.left and
      keys.right. if your KeyDown handler is form-wide, dont forget to set
      KeyPreview to true.
      [color=blue]
      > "Rlrcstr" wrote:
      >[color=green]
      > > How can you detect when an arrow key gets pressed? Doesn't seem to trigger
      > > a KeyPress or KeyDown event. Thanks.
      > >
      > > Jerry
      > >
      > >
      > >[/color][/color]

      Comment

      • Jerry Camel

        #4
        Re: Arrow Keys

        I'm not getting an event when the arrow is pressed. I do get one when the
        space bar is pressed, but not on an arrow press.

        Any thoughts?


        "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
        news:6BBDD76C-7207-4EE5-A39E-4367640E2B2E@mi crosoft.com...[color=blue]
        > sorry - posted too soon ... use the KeyDown event. check for keys.left
        > and
        > keys.right. if your KeyDown handler is form-wide, dont forget to set
        > KeyPreview to true.
        >[color=green]
        >> "Rlrcstr" wrote:
        >>[color=darkred]
        >> > How can you detect when an arrow key gets pressed? Doesn't seem to
        >> > trigger
        >> > a KeyPress or KeyDown event. Thanks.
        >> >
        >> > Jerry
        >> >
        >> >
        >> >[/color][/color][/color]


        Comment

        • AMercer

          #5
          Re: Arrow Keys

          I have no problems with KeyDown getting both arrow key events and space key.
          You get space but not arrow. What controls do you have on the form? Almost
          certainly the arrow keys are being intercepted by a control on your form.
          Search the .net help for "arrow and keydown" for interesting reading.

          Comment

          • Rlrcstr

            #6
            Re: Arrow Keys

            It's a usercontrol inside a scrollable panel container inside another
            usercontrol.

            I'm creating the inner usercontrols dynamically and then allowing the user
            to scroll through as many as have been created. Kinda like a listbox forthe
            usercontrols.

            I originally tried actually using an ownerdraw listbox - it has a controls
            collection - but it also has issues displaying controls when scrolling, so I
            decided to create my own.

            I'm very close but I still have to main issues and one of them is that I'm
            not getting the KeyDown trigger when an arrow is pressed. I don't
            understand why I would get other KeyDown events and not the arrows. It's
            strange seems that I get every other key. I even get modified arrows (i.e.
            Ctrl + Arrow) but nothing on a plain old arrow.

            I will search as you suggested, but in the mean time, if you have any other
            thoughts, I'm open...

            Jerry

            "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
            news:A3061506-B808-4F22-BB3C-B642913644B2@mi crosoft.com...[color=blue]
            >I have no problems with KeyDown getting both arrow key events and space
            >key.
            > You get space but not arrow. What controls do you have on the form?
            > Almost
            > certainly the arrow keys are being intercepted by a control on your form.
            > Search the .net help for "arrow and keydown" for interesting reading.[/color]


            Comment

            • Some Guy

              #7
              Re: Arrow Keys

              Override IsInputKey

              Protected Overrides Function IsInputKey(ByVa l keyData As
              System.Windows. Forms.Keys) As Boolean
              IsInputKey = True
              End Function

              "Rlrcstr" <rlrcstr@msn.co m> wrote in message
              news:urKZuv7ZFH A.2756@tk2msftn gp13.phx.gbl...[color=blue]
              > It's a usercontrol inside a scrollable panel container inside another
              > usercontrol.
              >
              > I'm creating the inner usercontrols dynamically and then allowing the user
              > to scroll through as many as have been created. Kinda like a listbox
              > forthe usercontrols.
              >
              > I originally tried actually using an ownerdraw listbox - it has a controls
              > collection - but it also has issues displaying controls when scrolling, so
              > I decided to create my own.
              >
              > I'm very close but I still have to main issues and one of them is that I'm
              > not getting the KeyDown trigger when an arrow is pressed. I don't
              > understand why I would get other KeyDown events and not the arrows. It's
              > strange seems that I get every other key. I even get modified arrows
              > (i.e. Ctrl + Arrow) but nothing on a plain old arrow.
              >
              > I will search as you suggested, but in the mean time, if you have any
              > other thoughts, I'm open...
              >
              > Jerry
              >
              > "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
              > news:A3061506-B808-4F22-BB3C-B642913644B2@mi crosoft.com...[color=green]
              >>I have no problems with KeyDown getting both arrow key events and space
              >>key.
              >> You get space but not arrow. What controls do you have on the form?
              >> Almost
              >> certainly the arrow keys are being intercepted by a control on your form.
              >> Search the .net help for "arrow and keydown" for interesting reading.[/color]
              >
              >[/color]


              Comment

              • Rlrcstr

                #8
                Re: Arrow Keys

                I started to read something about that. How can you do that with a control
                that is instantiated dynamically? Or do I have to create my own subclass?

                Thanks.

                Jerry


                "Some Guy" <myhouse@there. com> wrote in message
                news:119v8jfem2 4to3a@corp.supe rnews.com...[color=blue]
                > Override IsInputKey
                >
                > Protected Overrides Function IsInputKey(ByVa l keyData As
                > System.Windows. Forms.Keys) As Boolean
                > IsInputKey = True
                > End Function
                >
                > "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                > news:urKZuv7ZFH A.2756@tk2msftn gp13.phx.gbl...[color=green]
                >> It's a usercontrol inside a scrollable panel container inside another
                >> usercontrol.
                >>
                >> I'm creating the inner usercontrols dynamically and then allowing the
                >> user to scroll through as many as have been created. Kinda like a
                >> listbox forthe usercontrols.
                >>
                >> I originally tried actually using an ownerdraw listbox - it has a
                >> controls collection - but it also has issues displaying controls when
                >> scrolling, so I decided to create my own.
                >>
                >> I'm very close but I still have to main issues and one of them is that
                >> I'm not getting the KeyDown trigger when an arrow is pressed. I don't
                >> understand why I would get other KeyDown events and not the arrows. It's
                >> strange seems that I get every other key. I even get modified arrows
                >> (i.e. Ctrl + Arrow) but nothing on a plain old arrow.
                >>
                >> I will search as you suggested, but in the mean time, if you have any
                >> other thoughts, I'm open...
                >>
                >> Jerry
                >>
                >> "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
                >> news:A3061506-B808-4F22-BB3C-B642913644B2@mi crosoft.com...[color=darkred]
                >>>I have no problems with KeyDown getting both arrow key events and space
                >>>key.
                >>> You get space but not arrow. What controls do you have on the form?
                >>> Almost
                >>> certainly the arrow keys are being intercepted by a control on your
                >>> form.
                >>> Search the .net help for "arrow and keydown" for interesting reading.[/color]
                >>
                >>[/color]
                >
                >[/color]


                Comment

                • Some Guy

                  #9
                  Re: Arrow Keys

                  Yes, not hard. You don't even have to create a library to do it.


                  Public Class UserControl1
                  Inherits System.Windows. Forms.UserContr ol

                  Public Sub New()
                  Mybase.New()
                  End Sub

                  Protected Overrides Function IsInputKey(ByVa l keyData As
                  System.Windows. Forms.Keys) As Boolean
                  IsInputKey = True
                  End Function

                  End Class


                  Your form:

                  Dim Withevents myControl as UserControl1

                  mycontrol.Paren t = '-- Whatever
                  myControl.Locat ion = '-- Wherever
                  myControl.Size = '-- Whatever


                  "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                  news:Or97%23V%2 3ZFHA.2124@TK2M SFTNGP14.phx.gb l...[color=blue]
                  >I started to read something about that. How can you do that with a control
                  >that is instantiated dynamically? Or do I have to create my own subclass?
                  >
                  > Thanks.
                  >
                  > Jerry
                  >
                  >
                  > "Some Guy" <myhouse@there. com> wrote in message
                  > news:119v8jfem2 4to3a@corp.supe rnews.com...[color=green]
                  >> Override IsInputKey
                  >>
                  >> Protected Overrides Function IsInputKey(ByVa l keyData As
                  >> System.Windows. Forms.Keys) As Boolean
                  >> IsInputKey = True
                  >> End Function
                  >>
                  >> "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                  >> news:urKZuv7ZFH A.2756@tk2msftn gp13.phx.gbl...[color=darkred]
                  >>> It's a usercontrol inside a scrollable panel container inside another
                  >>> usercontrol.
                  >>>
                  >>> I'm creating the inner usercontrols dynamically and then allowing the
                  >>> user to scroll through as many as have been created. Kinda like a
                  >>> listbox forthe usercontrols.
                  >>>
                  >>> I originally tried actually using an ownerdraw listbox - it has a
                  >>> controls collection - but it also has issues displaying controls when
                  >>> scrolling, so I decided to create my own.
                  >>>
                  >>> I'm very close but I still have to main issues and one of them is that
                  >>> I'm not getting the KeyDown trigger when an arrow is pressed. I don't
                  >>> understand why I would get other KeyDown events and not the arrows.
                  >>> It's strange seems that I get every other key. I even get modified
                  >>> arrows (i.e. Ctrl + Arrow) but nothing on a plain old arrow.
                  >>>
                  >>> I will search as you suggested, but in the mean time, if you have any
                  >>> other thoughts, I'm open...
                  >>>
                  >>> Jerry
                  >>>
                  >>> "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
                  >>> news:A3061506-B808-4F22-BB3C-B642913644B2@mi crosoft.com...
                  >>>>I have no problems with KeyDown getting both arrow key events and space
                  >>>>key.
                  >>>> You get space but not arrow. What controls do you have on the form?
                  >>>> Almost
                  >>>> certainly the arrow keys are being intercepted by a control on your
                  >>>> form.
                  >>>> Search the .net help for "arrow and keydown" for interesting reading.
                  >>>
                  >>>[/color]
                  >>
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  • Rlrcstr

                    #10
                    Re: Arrow Keys

                    Makes perfect sense. Thanks.

                    Jerry


                    "Some Guy" <myhouse@there. com> wrote in message
                    news:119vi70co3 2utf2@corp.supe rnews.com...[color=blue]
                    > Yes, not hard. You don't even have to create a library to do it.
                    >
                    >
                    > Public Class UserControl1
                    > Inherits System.Windows. Forms.UserContr ol
                    >
                    > Public Sub New()
                    > Mybase.New()
                    > End Sub
                    >
                    > Protected Overrides Function IsInputKey(ByVa l keyData As
                    > System.Windows. Forms.Keys) As Boolean
                    > IsInputKey = True
                    > End Function
                    >
                    > End Class
                    >
                    >
                    > Your form:
                    >
                    > Dim Withevents myControl as UserControl1
                    >
                    > mycontrol.Paren t = '-- Whatever
                    > myControl.Locat ion = '-- Wherever
                    > myControl.Size = '-- Whatever
                    >
                    >
                    > "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                    > news:Or97%23V%2 3ZFHA.2124@TK2M SFTNGP14.phx.gb l...[color=green]
                    >>I started to read something about that. How can you do that with a
                    >>control that is instantiated dynamically? Or do I have to create my own
                    >>subclass?
                    >>
                    >> Thanks.
                    >>
                    >> Jerry
                    >>
                    >>
                    >> "Some Guy" <myhouse@there. com> wrote in message
                    >> news:119v8jfem2 4to3a@corp.supe rnews.com...[color=darkred]
                    >>> Override IsInputKey
                    >>>
                    >>> Protected Overrides Function IsInputKey(ByVa l keyData As
                    >>> System.Windows. Forms.Keys) As Boolean
                    >>> IsInputKey = True
                    >>> End Function
                    >>>
                    >>> "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                    >>> news:urKZuv7ZFH A.2756@tk2msftn gp13.phx.gbl...
                    >>>> It's a usercontrol inside a scrollable panel container inside another
                    >>>> usercontrol.
                    >>>>
                    >>>> I'm creating the inner usercontrols dynamically and then allowing the
                    >>>> user to scroll through as many as have been created. Kinda like a
                    >>>> listbox forthe usercontrols.
                    >>>>
                    >>>> I originally tried actually using an ownerdraw listbox - it has a
                    >>>> controls collection - but it also has issues displaying controls when
                    >>>> scrolling, so I decided to create my own.
                    >>>>
                    >>>> I'm very close but I still have to main issues and one of them is that
                    >>>> I'm not getting the KeyDown trigger when an arrow is pressed. I don't
                    >>>> understand why I would get other KeyDown events and not the arrows.
                    >>>> It's strange seems that I get every other key. I even get modified
                    >>>> arrows (i.e. Ctrl + Arrow) but nothing on a plain old arrow.
                    >>>>
                    >>>> I will search as you suggested, but in the mean time, if you have any
                    >>>> other thoughts, I'm open...
                    >>>>
                    >>>> Jerry
                    >>>>
                    >>>> "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
                    >>>> news:A3061506-B808-4F22-BB3C-B642913644B2@mi crosoft.com...
                    >>>>>I have no problems with KeyDown getting both arrow key events and space
                    >>>>>key.
                    >>>>> You get space but not arrow. What controls do you have on the form?
                    >>>>> Almost
                    >>>>> certainly the arrow keys are being intercepted by a control on your
                    >>>>> form.
                    >>>>> Search the .net help for "arrow and keydown" for interesting reading.
                    >>>>
                    >>>>
                    >>>
                    >>>[/color]
                    >>
                    >>[/color]
                    >
                    >[/color]


                    Comment

                    • Rlrcstr

                      #11
                      Re: Arrow Keys

                      I spoke too soon. It makes sense, but it doesn't seem to work.

                      I created the new class and replaced my New statement with the new class,
                      but the IsInputKey function in the subclass never gets called - I get the
                      same behavior. No arrows.

                      These controls are in a panel control. Do I have to subclass that guy? Is
                      it absorbing the keystrokes? Or do I have to subclass each of the child
                      controls (checkboxes and labels) on the new usercontrol and do the same
                      thing with them? This just seems so much more complicated that it should
                      be, just to capture an arrow key press.

                      Thanks.

                      Jerry



                      "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                      news:uSDA93KaFH A.2124@TK2MSFTN GP14.phx.gbl...[color=blue]
                      > Makes perfect sense. Thanks.
                      >
                      > Jerry
                      >
                      >
                      > "Some Guy" <myhouse@there. com> wrote in message
                      > news:119vi70co3 2utf2@corp.supe rnews.com...[color=green]
                      >> Yes, not hard. You don't even have to create a library to do it.
                      >>
                      >>
                      >> Public Class UserControl1
                      >> Inherits System.Windows. Forms.UserContr ol
                      >>
                      >> Public Sub New()
                      >> Mybase.New()
                      >> End Sub
                      >>
                      >> Protected Overrides Function IsInputKey(ByVa l keyData As
                      >> System.Windows. Forms.Keys) As Boolean
                      >> IsInputKey = True
                      >> End Function
                      >>
                      >> End Class
                      >>
                      >>
                      >> Your form:
                      >>
                      >> Dim Withevents myControl as UserControl1
                      >>
                      >> mycontrol.Paren t = '-- Whatever
                      >> myControl.Locat ion = '-- Wherever
                      >> myControl.Size = '-- Whatever
                      >>
                      >>
                      >> "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                      >> news:Or97%23V%2 3ZFHA.2124@TK2M SFTNGP14.phx.gb l...[color=darkred]
                      >>>I started to read something about that. How can you do that with a
                      >>>control that is instantiated dynamically? Or do I have to create my own
                      >>>subclass?
                      >>>
                      >>> Thanks.
                      >>>
                      >>> Jerry
                      >>>
                      >>>
                      >>> "Some Guy" <myhouse@there. com> wrote in message
                      >>> news:119v8jfem2 4to3a@corp.supe rnews.com...
                      >>>> Override IsInputKey
                      >>>>
                      >>>> Protected Overrides Function IsInputKey(ByVa l keyData As
                      >>>> System.Windows. Forms.Keys) As Boolean
                      >>>> IsInputKey = True
                      >>>> End Function
                      >>>>
                      >>>> "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                      >>>> news:urKZuv7ZFH A.2756@tk2msftn gp13.phx.gbl...
                      >>>>> It's a usercontrol inside a scrollable panel container inside another
                      >>>>> usercontrol.
                      >>>>>
                      >>>>> I'm creating the inner usercontrols dynamically and then allowing the
                      >>>>> user to scroll through as many as have been created. Kinda like a
                      >>>>> listbox forthe usercontrols.
                      >>>>>
                      >>>>> I originally tried actually using an ownerdraw listbox - it has a
                      >>>>> controls collection - but it also has issues displaying controls when
                      >>>>> scrolling, so I decided to create my own.
                      >>>>>
                      >>>>> I'm very close but I still have to main issues and one of them is that
                      >>>>> I'm not getting the KeyDown trigger when an arrow is pressed. I don't
                      >>>>> understand why I would get other KeyDown events and not the arrows.
                      >>>>> It's strange seems that I get every other key. I even get modified
                      >>>>> arrows (i.e. Ctrl + Arrow) but nothing on a plain old arrow.
                      >>>>>
                      >>>>> I will search as you suggested, but in the mean time, if you have any
                      >>>>> other thoughts, I'm open...
                      >>>>>
                      >>>>> Jerry
                      >>>>>
                      >>>>> "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
                      >>>>> news:A3061506-B808-4F22-BB3C-B642913644B2@mi crosoft.com...
                      >>>>>>I have no problems with KeyDown getting both arrow key events and
                      >>>>>>space key.
                      >>>>>> You get space but not arrow. What controls do you have on the form?
                      >>>>>> Almost
                      >>>>>> certainly the arrow keys are being intercepted by a control on your
                      >>>>>> form.
                      >>>>>> Search the .net help for "arrow and keydown" for interesting reading.
                      >>>>>
                      >>>>>
                      >>>>
                      >>>>
                      >>>
                      >>>[/color]
                      >>
                      >>[/color]
                      >
                      >[/color]


                      Comment

                      • Rlrcstr

                        #12
                        Re: Arrow Keys

                        Got it...

                        You have to override IsInputKey in the child controls and return true for
                        keys that you want the parent to see and then override processKeyPrevi ew in
                        the parent and look for those keystrokes.

                        Thanks for your help. On to the next hurdle...

                        Jerry

                        Have to override the processKeyPrevi ew event in the usercontrol
                        "Some Guy" <myhouse@there. com> wrote in message
                        news:119vi70co3 2utf2@corp.supe rnews.com...[color=blue]
                        > Yes, not hard. You don't even have to create a library to do it.
                        >
                        >
                        > Public Class UserControl1
                        > Inherits System.Windows. Forms.UserContr ol
                        >
                        > Public Sub New()
                        > Mybase.New()
                        > End Sub
                        >
                        > Protected Overrides Function IsInputKey(ByVa l keyData As
                        > System.Windows. Forms.Keys) As Boolean
                        > IsInputKey = True
                        > End Function
                        >
                        > End Class
                        >
                        >
                        > Your form:
                        >
                        > Dim Withevents myControl as UserControl1
                        >
                        > mycontrol.Paren t = '-- Whatever
                        > myControl.Locat ion = '-- Wherever
                        > myControl.Size = '-- Whatever
                        >
                        >
                        > "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                        > news:Or97%23V%2 3ZFHA.2124@TK2M SFTNGP14.phx.gb l...[color=green]
                        >>I started to read something about that. How can you do that with a
                        >>control that is instantiated dynamically? Or do I have to create my own
                        >>subclass?
                        >>
                        >> Thanks.
                        >>
                        >> Jerry
                        >>
                        >>
                        >> "Some Guy" <myhouse@there. com> wrote in message
                        >> news:119v8jfem2 4to3a@corp.supe rnews.com...[color=darkred]
                        >>> Override IsInputKey
                        >>>
                        >>> Protected Overrides Function IsInputKey(ByVa l keyData As
                        >>> System.Windows. Forms.Keys) As Boolean
                        >>> IsInputKey = True
                        >>> End Function
                        >>>
                        >>> "Rlrcstr" <rlrcstr@msn.co m> wrote in message
                        >>> news:urKZuv7ZFH A.2756@tk2msftn gp13.phx.gbl...
                        >>>> It's a usercontrol inside a scrollable panel container inside another
                        >>>> usercontrol.
                        >>>>
                        >>>> I'm creating the inner usercontrols dynamically and then allowing the
                        >>>> user to scroll through as many as have been created. Kinda like a
                        >>>> listbox forthe usercontrols.
                        >>>>
                        >>>> I originally tried actually using an ownerdraw listbox - it has a
                        >>>> controls collection - but it also has issues displaying controls when
                        >>>> scrolling, so I decided to create my own.
                        >>>>
                        >>>> I'm very close but I still have to main issues and one of them is that
                        >>>> I'm not getting the KeyDown trigger when an arrow is pressed. I don't
                        >>>> understand why I would get other KeyDown events and not the arrows.
                        >>>> It's strange seems that I get every other key. I even get modified
                        >>>> arrows (i.e. Ctrl + Arrow) but nothing on a plain old arrow.
                        >>>>
                        >>>> I will search as you suggested, but in the mean time, if you have any
                        >>>> other thoughts, I'm open...
                        >>>>
                        >>>> Jerry
                        >>>>
                        >>>> "AMercer" <AMercer@discus sions.microsoft .com> wrote in message
                        >>>> news:A3061506-B808-4F22-BB3C-B642913644B2@mi crosoft.com...
                        >>>>>I have no problems with KeyDown getting both arrow key events and space
                        >>>>>key.
                        >>>>> You get space but not arrow. What controls do you have on the form?
                        >>>>> Almost
                        >>>>> certainly the arrow keys are being intercepted by a control on your
                        >>>>> form.
                        >>>>> Search the .net help for "arrow and keydown" for interesting reading.
                        >>>>
                        >>>>
                        >>>
                        >>>[/color]
                        >>
                        >>[/color]
                        >
                        >[/color]


                        Comment

                        Working...