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. C# getting keyboard inputs

C# getting keyboard inputs

Scheduled Pinned Locked Moved C#
csharpquestion
4 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.
  • M Offline
    M Offline
    mercenary01
    wrote on last edited by
    #1

    How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel

    M S L 3 Replies Last reply
    0
    • M mercenary01

      How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! What's wrong with the code? What do you mean by "putting out" an event handler? Your implementation of OnKeyDown is a way to handle the KeyDown event...

      Regards, mav -- Black holes are the places where God divided by 0...

      1 Reply Last reply
      0
      • M mercenary01

        How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel

        S Offline
        S Offline
        satsumatable
        wrote on last edited by
        #3

        Like the below Convert.ToInt32 (e.KeyChar ) == 95 // this is for 'a' you can find constant integer valus of X and validate against it then proceed.

        1 Reply Last reply
        0
        • M mercenary01

          How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel

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

          Hi, there are several Keyboard events: - KeyDown and KeyUp events provide e.KeyCode (type Keys) and e.KeyValue (the int value of KeyCode); it also fires when pressing/releasing modifier keys (CTRL, ALT, SHIFT, ...) - for printable keys (the ones that normally add text in a text editor) you better use KeyPress event which provides e.KeyChar (char), so you dont need to refer to the Keys enumeration nor the explicit conversion to integers. :)

          Luc Pattyn


          try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


          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