如何将密钥代码转换为.NET中的keychar?
在VB.NET中:
ChrW(70)
在C#中你可以施放:
(char) 70
我使用user32.dll的库类解决了这个问题.我更喜欢Framework类,但找不到一个,所以这对我有用.
Imports System.Runtime.InteropServices Public Class KeyCodeToAscii_ 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 End Function _ Public Shared Function GetKeyboardState(ByVal pbKeyState As Byte()) _ As Integer End Function Public Shared Function GetAsciiCharacter(ByVal uVirtKey As Integer) _ As Char Dim lpKeyState As Byte() = New Byte(255) {} GetKeyboardState(lpKeyState) Dim lpChar As Byte() = New Byte(1) {} If ToAscii(uVirtKey, 0, lpKeyState, lpChar, 0) = 1 Then Return Convert.ToChar((lpChar(0))) Else Return New Char() End If End Function End Class