我已经使用SetWindowsHookEx()函数实现了一个低级键盘钩子。它工作得很好,每次击键都会返回一个虚拟键码。我可以使用KeyInterop.KeyFromVirtualKey()将这个虚拟密钥代码转换为System.Windows.Input.Key。但目标是在当前键盘布局中获得与此虚拟键码相对应的符号。
例如,对于德国布局,我想将Key.Z设置为"Y“,将Key.Y设置为"Z”。
有人能帮上忙吗?
谢谢。
发布于 2012-01-03 05:50:40
你应该看看这个方法GetKeyboardState,GetKeyboardLayout,MapVirtualKeyEx,ToUnicodeEx。
解决方案应该看起来像这样
byte[] keyboardState = new byte[256];
GetKeyboardState(keyboardState);
IntPtr handle = GetKeyboardLayout(0);
uint scanCode = MapVirtualKeyEx(VirtualKeyCode, 0, handle);
StringBuilder stringBuilder = new StringBuilder(2);
int nResultLower = ToUnicodeEx(VirtualKeyCode, scanCode, keyboardState, stringBuilder,
stringBuilder.Capacity, 0, handle);
string output= string.Empty;
if (nResultLower != 0)
{
output = stringBuilder.ToString();
}https://stackoverflow.com/questions/1164172
复制相似问题