Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. KeyPress

KeyPress

Scheduled Pinned Locked Moved C#
question
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mazdak
    wrote on last edited by
    #1

    I wanna check for pressing arrow keys in KeyPress event. How can I do it? :) Thanks Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

    E 1 Reply Last reply
    0
    • M Mazdak

      I wanna check for pressing arrow keys in KeyPress event. How can I do it? :) Thanks Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

      E Offline
      E Offline
      ez2
      wrote on last edited by
      #2

      I think you can do something like this if(e.KeyCode == Keys.Right) { DoSomething..... }

      M 2 Replies Last reply
      0
      • E ez2

        I think you can do something like this if(e.KeyCode == Keys.Right) { DoSomething..... }

        M Offline
        M Offline
        Mazdak
        wrote on last edited by
        #3

        Thanks :) Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

        1 Reply Last reply
        0
        • E ez2

          I think you can do something like this if(e.KeyCode == Keys.Right) { DoSomething..... }

          M Offline
          M Offline
          Mazdak
          wrote on last edited by
          #4

          ez2 wrote: if(e.KeyCode == Keys.Right) Sorry,It doesn't exist in System.Windows.Forms.KeyPressEventArgs,So How can I use it?:confused: Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

          E 1 Reply Last reply
          0
          • M Mazdak

            ez2 wrote: if(e.KeyCode == Keys.Right) Sorry,It doesn't exist in System.Windows.Forms.KeyPressEventArgs,So How can I use it?:confused: Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

            E Offline
            E Offline
            ez2
            wrote on last edited by
            #5

            mazdak, I just checked and your right. It looks as though keyPressEventArgs only handles characters (i.e. e.KeyChar returns a char) and not other keys like ALT, Arrows, etc. Not sure why that is so I will do some checking. Alternatively, you could use the Keydown event which does have a KeyEventArgs and you can trap additional keys. In that case, if(e.KeyCode == Keys.Right) should work. I need some clarification myself on keydown vs. keypress anyway so I will let you know what I find.

            R 1 Reply Last reply
            0
            • E ez2

              mazdak, I just checked and your right. It looks as though keyPressEventArgs only handles characters (i.e. e.KeyChar returns a char) and not other keys like ALT, Arrows, etc. Not sure why that is so I will do some checking. Alternatively, you could use the Keydown event which does have a KeyEventArgs and you can trap additional keys. In that case, if(e.KeyCode == Keys.Right) should work. I need some clarification myself on keydown vs. keypress anyway so I will let you know what I find.

              R Offline
              R Offline
              Rupel
              wrote on last edited by
              #6

              jap - thats the way it goes. keypressed is somewhat focussing on characters (in fact, the type of the KeyChar-property is char) special keys (like arrows/functionkeys/etc.) you can only handle using keyup/keydown (the KeyCode-property in there is of the Keys type) :wq

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups