1
기본 배경 키로거를 쓰려고합니다 ... 키보드 스캔 코드와 상태는 pinvoke 함수 ToAsciiEx 또는 ToUnicodeEx를 통해 변환됩니다. 이 함수에는 KeyboardLayout에 대한 인수가 있습니다. 현재 (활성 창) 키보드 레이아웃을 가져 오는 기능 (아래 참조)이 있습니다. 그러나이 함수는 항상 0을 반환합니다. 오류 코드는 6입니다 (ERROR_INVALID_HANDLE).pinvoke 함수의 오류 getKeyBoardLayout()
당신은 함수에 프로세스 ID를 전달하는 답변
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;
}
답장을 보내 주셔서 감사합니다. 제 문제가 해결되었습니다. 이제 코드가 더 단순 해 보입니다. 'uint tid = GetWindowThreadProcessId (GetForegroundWindow(), IntPtr.Zero); IntPtr layout = GetKeyboardLayout (tid); 반환 레이아웃; – ijavid