我正在设计一个屏幕键盘,
我想将按键字符更改为与按键后将在屏幕上打印的字符相同
即按钮A将返回英文“A”,法文“Q”
我需要一个返回字符串的函数描述结果,它的参数是关键和当前的文化
另外,如果有可能知道按下班次后会发生什么是一个很好的加分项
我用过这段代码
[DllImport("user32.dll")]
public static extern int ToUnicode(uint virtualKeyCode, ScanCodeShort scanCode,
byte[] keyboardState,
[Out, MarshalAs(UnmanagedType.LPWStr, SizeConst = 64)]
StringBuilder receivingBuffer,
int bufferSize, uint flags);
public static string GetCharsFromKeys(ScanCodeShort keys)
{
var buf = new StringBuilder(256);
var keyboardState = new byte[256];
GetKeyState(VirtualKeyStates.VK_F3);
GetKeyboardState(keyboardState);
keyboardState[(int)System.Windows.Forms.Keys.ControlKey] = 0x00;
int x = ToUnicode(MapVirtualKey(keys, 1), keys, keyboardState, buf, 256, 0);
return buf.ToString();
}
[DllImport("user32.dll")]
static extern short GetKeyState(VirtualKeyStates nVirtKey);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetKeyboardState(byte[] lpKeyState);
在调用阶段,我使用 GetCharsFromKeys(ScanCodeShort keys) 其中 ScanCodeShort 是扫描码,而不是虚拟码