问题
I need to send a key to an inactive "ePSXe" window using C#. I got the handle of the window using Spy++, but when I used this code to send key "x", I got nothing. What should I do?
I tried different values of Msg
as 0x0100
, 0x0101
and 0x0102
, but nothing worked. I also tried SendMessage
and the results were the same.
[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
private void Send_X(IntPtr p)
{
PostMessage(p, 0x0100, (IntPtr)Keys.X, IntPtr.Zero);
}
I expect the window to respond to my key. I managed only to send F keys "F1, F2..", but not letter keys.
SendMessage(p, 0x0100, (IntPtr)Keys.F4, IntPtr.Zero);
SendMessage(p, 0x0101, (IntPtr)Keys.F4, IntPtr.Zero);
I think sending to an inactive game application is not easy, however this solution helped me a lot, but I have to focus ePSXe. Sending keys to a DirectX Game.
I am still looking for a solution that can send to an inactive game window.
回答1:
Process P = ...get process;
IntPtr whandle= P.MainWindowHandle;
PostMessage(whandle, WM_KEYDOWN, (IntPtr)(Keys.X), IntPtr.Zero);
It works if you have MainWindowHandle
of that process, otherwise not.
来源:https://stackoverflow.com/questions/56613401/how-can-i-send-keys-to-inactive-directx-epsxe-window