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. RichTextBox e

RichTextBox e

Scheduled Pinned Locked Moved C#
question
7 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
    mihksoft
    wrote on last edited by
    #1

    Hy I have a RichTextBox. When I press any alphabetic key on RichTextBox_KeyDown the e.KeyValue have the ascci code for the bigger letter. I press "q" and the e.KeyValue have the ascci code for "Q". How can I detect what key I pressed? thanks

    P G L 3 Replies Last reply
    0
    • M mihksoft

      Hy I have a RichTextBox. When I press any alphabetic key on RichTextBox_KeyDown the e.KeyValue have the ascci code for the bigger letter. I press "q" and the e.KeyValue have the ascci code for "Q". How can I detect what key I pressed? thanks

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      :confused:You've already identified what key you've pressed. Do you mean how do you work out what character it was? If so, just cast it to a string.

      Deja View - the feeling that you've seen this post before.

      M 1 Reply Last reply
      0
      • P Pete OHanlon

        :confused:You've already identified what key you've pressed. Do you mean how do you work out what character it was? If so, just cast it to a string.

        Deja View - the feeling that you've seen this post before.

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

        I cast to string. When I press "q" the e.KeyValue = 81 ... the ascci code for "Q". So I can detect If i press down "q" or "Q".

        1 Reply Last reply
        0
        • M mihksoft

          Hy I have a RichTextBox. When I press any alphabetic key on RichTextBox_KeyDown the e.KeyValue have the ascci code for the bigger letter. I press "q" and the e.KeyValue have the ascci code for "Q". How can I detect what key I pressed? thanks

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #4

          e.Keycode

          #region signature my articles #endregion

          M 1 Reply Last reply
          0
          • G Giorgi Dalakishvili

            e.Keycode

            #region signature my articles #endregion

            M Offline
            M Offline
            mihksoft
            wrote on last edited by
            #5

            e.KeyCode and e.KeyValue have the same ascci value

            G 1 Reply Last reply
            0
            • M mihksoft

              Hy I have a RichTextBox. When I press any alphabetic key on RichTextBox_KeyDown the e.KeyValue have the ascci code for the bigger letter. I press "q" and the e.KeyValue have the ascci code for "Q". How can I detect what key I pressed? thanks

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

              Hi, KeyDown/KeyUp events offer a KeyEventArgs with amongst others these key information properties: · Keys KeyCode: the keyboard code · Keys KeyData: the key data (i.e. the key that was pressed, combined with modifier flags that indicate which combination of CTRL, SHIFT, and ALT keys was pressed at the same time.) · int KeyValue: the integer representation of the KeyCode property KeyPress events offer a KeyPressEventArgs with amongst others these key information properties: · char KeyChar: the character (with correct casing) The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events. The typical use would be to process KeyDown to handle special keys (such as Enter, Backspace, and CTRL/X combinations), and to process KeyPress to consume regular keys (as in adding characters to text) :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google


              1 Reply Last reply
              0
              • M mihksoft

                e.KeyCode and e.KeyValue have the same ascci value

                G Offline
                G Offline
                Giorgi Dalakishvili
                wrote on last edited by
                #7

                You have only one key on the keyboard so that's why you are getting the same value. You can check for caps lock like this: Control.IsKeyLocked(Keys.CapsLock) and extract information about shift button from e.Keydata. Based on these two pieces of information you will be able to determine whether 'q' was typed or 'Q'

                #region signature my articles #endregion

                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