Ascii Codes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sgrec7
    New Member
    • Aug 2007
    • 58

    Ascii Codes

    hi guys,

    hey i looked everywere and i can't for the life of me find the ascii codes for these keys:

    ctrl (the control button, bottom left corner of keyboard)

    alt (the alt button, either side of the spacebar)

    thanks guys, even if you link me the URL for a site that will help

    thanks again in advance

    sgrec7
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by sgrec7
    hi guys,

    hey i looked everywere and i can't for the life of me find the ascii codes for these keys:

    ctrl (the control button, bottom left corner of keyboard)

    alt (the alt button, either side of the spacebar)

    thanks guys, even if you link me the URL for a site that will help

    thanks again in advance

    sgrec7
    ctrl ---> 17
    alt ---> 18

    you can have it on a text box if you write in some other controls KeyDown event something like

    textbox1.text = keycode

    then just select that control an press the key you want to know ;)

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      These keys don't have ASCII codes.

      ASCII defines values for the character set. These are keyboard keys, not characters.

      The difference between KeyDown and KeyPress events is that one reports the actual key pressed, while the other reports the ASCII character which was generated as a result. For example, pressing the "A" key generates the keycode for that key (65). Depending on the current state of the Caps-Lock, Shift, Control and Alt and Shift keys, the ASCII character generated might be...
      "A" (code 65), "a" (code 97), "Ctrl-A" (code 1) or whatever.

      This is why keys such as Shift, Alt and so on do not trigger a KeyPress event.

      Comment

      • sgrec7
        New Member
        • Aug 2007
        • 58

        #4
        yea thanks guys...

        i want to use alt and ctrl in a keyprss event

        will it still work ???

        Comment

        • hariharanmca
          Top Contributor
          • Dec 2006
          • 1977

          #5
          Originally posted by sgrec7
          yea thanks guys...

          i want to use alt and ctrl in a keyprss event

          will it still work ???
          You can try Key down and key up event using

          KeyCode = vbKeyControl ==>> Control
          KeyCode = vbKeyMenu ==>> Alt

          there you find two perameter for key pressed and shift pressed

          I think this will help you.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by sgrec7
            i want to use alt and ctrl in a keyprss event
            Are you sure you can't do it in the KeyDown or KeyUp event?

            If you want, you can put code in your KeyPress event procedure to test the current state of these keys. I forget how, but detecting the current state of keys was covered here not too long ago. Maybe a couple of months back. Try some searches.

            Comment

            • QVeen72
              Recognized Expert Top Contributor
              • Oct 2006
              • 1445

              #7
              Hi,

              U have to check the Shift in KeyUp event :
              Values would be:
              A C S
              4 2 1

              [code=vb]
              Private Sub Text1_KeyUp(Key Code As Integer, Shift As Integer)
              Select Case Shift
              Case 1
              MsgBox "Shift Pressed"
              Case 2
              MsgBox "Control Pressed"
              Case 3
              MsgBox "Shift + Control Pressed"
              Case 4
              MsgBox "Alt Pressed"
              Case 5
              MsgBox "Alt + Shift Pressed"
              Case 6
              MsgBox "Alt+Contro l Pressed"
              Case 7
              MsgBox "Alt+Shift+Cont rol Pressed"
              End Select
              End Sub
              [/code]

              REgards
              Veena

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                There's also an API function you can call to check the current key state. I just don't remember what it's called.

                Comment

                • sgrec7
                  New Member
                  • Aug 2007
                  • 58

                  #9
                  Originally posted by Killer42
                  Are you sure you can't do it in the KeyDown or KeyUp event?

                  If you want, you can put code in your KeyPress event procedure to test the current state of these keys. I forget how, but detecting the current state of keys was covered here not too long ago. Maybe a couple of months back. Try some searches.
                  or you could just tell me !!! :-) that would be MUCH easer... for me !!! :-)

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Originally posted by sgrec7
                    or you could just tell me !!! :-) that would be MUCH easer... for me !!! :-)
                    It certainly would. If I could remember it. I do remember it had "Asynch" in the name, but that's probably not a lot of help.

                    Comment

                    • Killer42
                      Recognized Expert Expert
                      • Oct 2006
                      • 8429

                      #11
                      Ok, I spent some time searching, and managed to track down the thread I was thinking of. Here it is.

                      I hope it's some help.

                      Comment

                      • QVeen72
                        Recognized Expert Top Contributor
                        • Oct 2006
                        • 1445

                        #12
                        Originally posted by sgrec7
                        or you could just tell me !!! :-) that would be MUCH easer... for me !!! :-)
                        Hi,

                        did u check my post above...?


                        Regards
                        Veena

                        Comment

                        • kadghar
                          Recognized Expert Top Contributor
                          • Apr 2007
                          • 1302

                          #13
                          Originally posted by sgrec7
                          or you could just tell me !!! :-) that would be MUCH easer... for me !!! :-)
                          In my first post i wrote what the KeyCode were, and as Killer said, they dont have an ascii code, only a KeyCode. (the keycodes are 17 and 18), and im not sure they'll work in keypress, you should use them in keydown

                          Comment

                          • sgrec7
                            New Member
                            • Aug 2007
                            • 58

                            #14
                            Originally posted by kadghar
                            In my first post i wrote what the KeyCode were, and as Killer said, they dont have an ascii code, only a KeyCode. (the keycodes are 17 and 18), and im not sure they'll work in keypress, you should use them in keydown
                            Thanks to all of you, but after reading through all that I think we will come to an agreement that space bar (32) will be much easier to deal with

                            thanks to you all again

                            sgrec7

                            Comment

                            Working...