Results 1 to 2 of 2

Thread: Plus key & code 187?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Plus key & code 187?

    I cannot find documentation for some KeyCodes I used in an application I wrote 2-3 years ago. There might be other useful data in such documentation.

    In a KeyDown Event Subroutine, my code has the following If Statement.
    VB Code:
    1. If KeyCode = vbKeyAdd Or KeyCode = 187 Then
    2.             ‘Code for Plus-Key
    3.         ElseIf KeyCode = vbKeySubtract Or KeyCode = 189 Then
    4.             ‘Code for Minus-Key
    5.         Else
    6.     End If
    The above does just what I want, but I no longer remember how I decided to use KeyCodes 187 & 189.

    187 seems to relate to the Keyboard key with + = on it.
    189 seems to relate to the Key with _ - on it.

    My Visual Basic 6.0 Language Reference Manual shows codes 187 189 to be >> 1/2

    The code works if the above keys are used with or without a shift key.

    Where is there documentation about things like the above?
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    The KeyDown event has the KeyCode parameter. The KeyPress event has the KeyAscii parameter. Technically, they are not the same thing, although many keycode constants have the same Ascii value (numeric keys 0-9 and capitol letters A-Z) many do not.

    As you noted,

    KeyAscii 187 is >>, KeyCode 187 is the += key (the ascii code for the + sign is 43).

    The constant vbKeyAdd refers to the + key on the keypad. You probably used "Or KeyCode = 187" because there is no intrinsic constant for the += key. Thus your code handles both + key's that are available on a keyboard. If however, you needed to distinguish between the = and +, then you would need to check the Shift parameter of the KeyDown event.

    To duplicate your code in the KeyDown event into the KeyPress event you would need to write ( again this forces the user to do a Shift +, if not using the keypad)

    If Keyascii = 43 Then

    ElseIf Keyascii = 45 Then
    ..

    There are topics in msdn called KeyCode Constants and Ascii Character Codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width