How can I send keys to inactive DirectX “ePSXe” window?

泄露秘密 提交于 2020-01-14 05:29:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!