intercepting keys

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • maxhodges

    intercepting keys

    I need to access some unicode characters from the keyboard for single
    textbox on a form I've built. I've done this before using the code
    below, but now I need to substitute the forward slash and period
    character ("/", ".") but I can't find the named constant for these
    characters in the KEYS data type. Anyone know that their name is? Or a
    good workaround?

    Thanks,
    maxhodges
  • Shawn D Shelton

    #2
    Re: intercepting keys

    You could try something like

    Private Sub txtUser_KeyPres s(ByVal sender As System.Object, ByVal e As
    System.Windows. Forms.KeyPressE ventArgs) Handles txtUser.KeyPres s
    Dim KeyAscii As Integer = Asc(e.KeyChar)

    If KeyAscii = 46 Then ' The period
    KeyAscii = 0 'place whatever ascii value you want
    End If
    If KeyAscii = 92 Then ' The backslash.
    KeyAscii = 0 'place whatever ascii value you want
    End If

    If KeyAscii = 0 Then
    e.Handled = True
    End If
    End Sub

    maxhodges wrote:
    [color=blue]
    > I need to access some unicode characters from the keyboard for single
    > textbox on a form I've built. I've done this before using the code
    > below, but now I need to substitute the forward slash and period
    > character ("/", ".") but I can't find the named constant for these
    > characters in the KEYS data type. Anyone know that their name is? Or a
    > good workaround?
    >
    > Thanks,
    > maxhodges[/color]

    Comment

    • Fergus Cooney

      #3
      Re: intercepting keys

      Hi Max,

      I believe you'll find that these are the obviously named Keys.Decimal and
      Keys.Divide. ;-)

      I don't think they called the '\' character Keys.IntegerDiv ide, though!

      Unfortunately it's less useful than at first sight. Keys.Divide is the key
      on the numeric keypad and Keys.Decimal is similarly on the numeric keypad but
      only when NumLock is on.

      In KeyDown you can use
      If e.KeyCode = 191 Then .. 'Main keyboard '/'
      If e.KeyCode = 111 Then .. 'Num keypad '/'
      If e.KeyCode = 110 Then .. 'Num keypad '.' NumLock on
      If e.KeyCode = 46 Then .. 'Num keypad '.' NumLock off

      But only if you're using <my> keyboard or those configured the same way!

      In KeyPress you can use
      If e.KeyChar = "/" Then ..
      If e.KeyChar = "." Then ..

      Regards,
      Fergus


      Comment

      Working...