pinvoke函数getKeyBoardLayout()的错误
我正在尝试编写一个基本的背景键盘记录器...键盘scanCodes和States通过pinvoke函数ToAsciiEx或ToUnicodeEx进行转换。这些函数有一个KeyboardLayout参数。我有一个功能(见下文)获取当前(活动窗口)键盘布局。但此函数始终返回0.错误代码为6(ERROR_INVALID_HANDLE)。
任何sugessions?
thx的答案
static public IntPtr getActiveKeyBoardLayout()
{
int handle = 0;
handle = GetForegroundWindow();
IntPtr i = new IntPtr(handle);
HandleRef hr = new HandleRef(wrapper, i);
int pid;
GetWindowThreadProcessId(hr, out pid);
IntPtr layout = GetKeyboardLayout(pid);
int er = Marshal.GetLastWin32Error();
if (er > 0)
{
System.Console.Out.WriteLine("error " + er.ToString());
}
return layout;
}
没有找到相关结果
已邀请:
1 个回复
拭十年