code_junkie

convert keycode to key char

Nov 12th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. Convert.ToChar(65)
  2.  
  3. ChrW(70)
  4.  
  5. (char) 70
  6.  
  7. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
  8. Public sub harry()
  9. For i = 1 to 255
  10. If Chr(i) = Convert.ToChar(Keys.Enter) Then
  11. Label1.Text &= " [Enter] "
  12. ElseIf Chr(i) = Convert.ToChar(Keys.Delete) Then
  13. Label1.Text &= " [Delete] "
  14. End If
  15. Next i
  16. End Sub
  17.  
  18. Private Sub StartValue_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles StartValue.KeyPress
  19. If ChrW(13).ToString = e.KeyChar And StartValue.Text = "" Then
  20. StartValue.Text = "0"
  21. End If
  22. End Sub
  23.  
  24. Imports System.Runtime.InteropServices
  25.  
  26. Public Class KeyCodeToAscii
  27. <DllImport("User32.dll")> _
  28. Public Shared Function ToAscii(ByVal uVirtKey As Integer, ByVal uScanCode As Integer, ByVal lpbKeyState As Byte(), ByVal lpChar As Byte(), ByVal uFlags As Integer) As Integer
  29. End Function
  30.  
  31. <DllImport("User32.dll")> _
  32. Public Shared Function GetKeyboardState(ByVal pbKeyState As Byte()) As Integer
  33. End Function
  34.  
  35. Public Shared Function GetAsciiCharacter(ByVal uVirtKey As Integer) As Char
  36. Dim lpKeyState As Byte() = New Byte(255) {}
  37. GetKeyboardState(lpKeyState)
  38. Dim lpChar As Byte() = New Byte(1) {}
  39. If ToAscii(uVirtKey, 0, lpKeyState, lpChar, 0) = 1 Then
  40. Return Convert.ToChar((lpChar(0)))
  41. Else
  42. Return New Char()
  43. End If
  44. End Function
  45. End Class
Add Comment
Please, Sign In to add comment