Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi everybody

 

I need to know when user types the underline character ( '_', ASCII code 95), but when I receive the events KeyDown, KeyPress or KeyDown, all that I get is key codes (i.e. OemMinus, code 189).

 

I know that when the OemMinus is pressed and the "Shift" key is also pressed, then the user is typing the underline character, but I want a more general method ( API? ) to translate any KeyData / KeyCode or KeyValue into the ASCII code of the character typed by user.

 

Thanks in advance

 

Luis B. Chicaiza

  • Administrators
Posted

To detect a key you can use

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
	If e.KeyChar = "_" Then    'will get the _ key

	End If
End Sub

 

To get the ascii value you can use

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
Dim b() As Byte = System.Text.Encoding.ASCII.GetBytes(e.KeyChar)
'b(0) will now equal the ascii code 
End Sub

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...