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. How to get a code of pressed key ?

How to get a code of pressed key ?

Scheduled Pinned Locked Moved C#
questiontutorial
5 Posts 4 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.
  • S Offline
    S Offline
    Saikek
    wrote on last edited by
    #1

    Hello. How can i get a code of pressed key ? :confused:

    One nation - underground

    R K L 3 Replies Last reply
    0
    • S Saikek

      Hello. How can i get a code of pressed key ? :confused:

      One nation - underground

      R Offline
      R Offline
      Russell Jones
      wrote on last edited by
      #2

      http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.keydown(VS.71).aspx like that? Russell

      1 Reply Last reply
      0
      • S Saikek

        Hello. How can i get a code of pressed key ? :confused:

        One nation - underground

        K Offline
        K Offline
        kifahhk
        wrote on last edited by
        #3

        try this this is a small key pressed event private void cbfilmoname_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar==0xd) { mymethod(); } } // "0xd" means that the Key Pressed is "ENTER" key // you can find the KeyChar of the any key with tracing this code // or in help documents

        1 Reply Last reply
        0
        • S Saikek

          Hello. How can i get a code of pressed key ? :confused:

          One nation - underground

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, there are 3 keyboard events: KeyDown, KeyPress, KeyUp the documentation states: The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events. noncharacter keys include shift, alt, control, shift lock, ... KeyDown and KeyUp offer KeyCode, KeyChar and KeyValue properties; KeyPress only offers KeyChar. The rationale seems to be special characters can be recognized during KeyDown/Up, whereas KeyPress only is fired for normal characters, where KeyCode would not be relevant. But the KeyPressEventArgs does offer information on the state of the modifier keys (Control, Alt, Shift). Note: normal characters have autorepeat, the special ones dont. Warning: the KeyPress event fires when the key gets released (or the autorepeat delay is reached). The KeyDown event fires immediately when the key goes down. Conclusion: if you really need KeyCode, use KeyDown event. :)

          Luc Pattyn [My Articles]

          S 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, there are 3 keyboard events: KeyDown, KeyPress, KeyUp the documentation states: The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events. noncharacter keys include shift, alt, control, shift lock, ... KeyDown and KeyUp offer KeyCode, KeyChar and KeyValue properties; KeyPress only offers KeyChar. The rationale seems to be special characters can be recognized during KeyDown/Up, whereas KeyPress only is fired for normal characters, where KeyCode would not be relevant. But the KeyPressEventArgs does offer information on the state of the modifier keys (Control, Alt, Shift). Note: normal characters have autorepeat, the special ones dont. Warning: the KeyPress event fires when the key gets released (or the autorepeat delay is reached). The KeyDown event fires immediately when the key goes down. Conclusion: if you really need KeyCode, use KeyDown event. :)

            Luc Pattyn [My Articles]

            S Offline
            S Offline
            Saikek
            wrote on last edited by
            #5

            Thanks to all for their answers !!

            One nation - underground

            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