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. Visual Basic
  4. Key press problem

Key press problem

Scheduled Pinned Locked Moved Visual Basic
helptutorialquestion
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.
  • P Offline
    P Offline
    Pasan148
    wrote on last edited by
    #1

    I have a problem that how to determine which key pressed by user. I have already used 'Keys' enumerator and 'Keycode' property of 'KeyEventArgs' class. It was returned key code only. if user pressed 'A' key, it returned 65. But how can i know that user pressed 'A' or 'a'. In this case i have disabled typing in Text box. Somebody have any idea.

    D L L 3 Replies Last reply
    0
    • P Pasan148

      I have a problem that how to determine which key pressed by user. I have already used 'Keys' enumerator and 'Keycode' property of 'KeyEventArgs' class. It was returned key code only. if user pressed 'A' key, it returned 65. But how can i know that user pressed 'A' or 'a'. In this case i have disabled typing in Text box. Somebody have any idea.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I don't know which event you're handling, but the KeyEventArgs class has a Modifiers property which will tell you if the Ctrl, Shift, or Alt keys are down at the time the key was up or down.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      1 Reply Last reply
      0
      • P Pasan148

        I have a problem that how to determine which key pressed by user. I have already used 'Keys' enumerator and 'Keycode' property of 'KeyEventArgs' class. It was returned key code only. if user pressed 'A' key, it returned 65. But how can i know that user pressed 'A' or 'a'. In this case i have disabled typing in Text box. Somebody have any idea.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You are probably going to have to be a bit more specific in what you are trying to do.

        Pasan148 wrote:

        if user pressed 'A' key, it returned 65

        That is correct since 65 is the ASCII code for A

        Pasan148 wrote:

        how can i know that user pressed 'A' or 'a'

        If the user entered a lower case 'a' the ASCII code would be 97.

        Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here

        1 Reply Last reply
        0
        • P Pasan148

          I have a problem that how to determine which key pressed by user. I have already used 'Keys' enumerator and 'Keycode' property of 'KeyEventArgs' class. It was returned key code only. if user pressed 'A' key, it returned 65. But how can i know that user pressed 'A' or 'a'. In this case i have disabled typing in Text box. Somebody have any idea.

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

          The KeyPress event passses a KeyPressEventArgs which holds the KeyChar, i.e. the char that the user intends when he types a key or key combination that produces some text. This is the event you should use to consume text input. The KeyDown and KeyUp events also fire for key actions that don't produce visible text, such as the control key. They hold a KeyEventArgs that has all possible information about a key and the key modifiers. These are the events you could use to filter keyboard input. BTW: Control.ModifierKeys is always up to date, but seldom needed. PS: is something wrong with the documentation? did Google break down? Read up on the classes you use! :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          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