110,567
社区成员
发帖
与我相关
我的任务
分享
WinAPI.AttachThreadInput((uint)_p.Id, (uint)selfPID, true);
IntPtr focusdhandle = WinAPI.GetFocus();
WinAPI.AttachThreadInput((uint)_p.Id, (uint)selfPID, false);
Console.WriteLine(focusdhandle);
Process _p = Process.GetProcessById(pInfo.dwProcessId);
while (!_p.HasExited)
{
if (_p.MainWindowHandle.ToInt32() != 0)
{
mainWindowHandle = _p.MainWindowHandle;
break;
}
}
_p.WaitForInputIdle();
WinAPI.PostMessageSafe(mainWindowHandle, 0x0100, 0x41, 0);
_p.WaitForExit();
private static void SetHook(PROCESS_INFORMATION pInfo)
{
WinAPI.HookProc hook = myHookProc;
Process p = Process.GetProcessById(pInfo.dwProcessId);
IntPtr modelhandle = WinAPI.GetModuleHandle(p.MainModule.ModuleName);//获取不到,一直返回 0
curHook = WinAPI.SetWindowsHookEx(HookType.WH_KEYBOARD, myHookProc, modelhandle, (uint)pInfo.dwThreadId);
int error = Marshal.GetLastWin32Error();
if (error != 0)
{
throw new Win32Exception(error);
}
}
private static IntPtr myHookProc(int code, IntPtr wParam, IntPtr lParam)
{
Keys key = (Keys)wParam.ToInt32();
Console.WriteLine(key);
return WinAPI.CallNextHookEx(IntPtr.Zero, code, wParam, lParam);
}