所以我遇到了一个问题,我正在尝试将密钥发送到游戏中,并且我将游戏放在前台,SetForegroundWindow并且我正在使用SendInputsAPI将密钥发送到游戏中.
如果我专注于另一个应用程序,密钥将被发送到该应用程序,但只要我专注于我想要发送密钥的应用程序,它们就不会出现在那里.
我想节省一些时间为我的公会招募公会成员,并且我正试图将钥匙发送给游戏.
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern IntPtr GetMessageExtraInfo();
[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
Process[] procs = Process.GetProcessesByName("BlackDesert64");
if (procs.Length > 0)
{
if (procs[0].MainWindowHandle != IntPtr.Zero)
{
SetForegroundWindow(procs[0].MainWindowHandle);
Thread.Sleep(1000);
}
}
INPUT[] inputs = new INPUT[]
{
new INPUT
{
type = INPUT_KEYBOARD,
u = new InputUnion
{
ki = new KEYBDINPUT
{
wVk = 0x49,
wScan = 0049,
dwFlags = KEYEVENTF_UNICODE,
dwExtraInfo = GetMessageExtraInfo(),
}
}
},
new INPUT
{
type = INPUT_KEYBOARD,
u = new InputUnion
{
ki = new KEYBDINPUT
{
wVk = 0x49,
wScan = 0049,
dwFlags = KEYEVENTF_KEYUP,
dwExtraInfo = GetMessageExtraInfo(),
}
}
}
};
SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
Run Code Online (Sandbox Code Playgroud)
其余代码:https: //pastebin.com/RUm7A311
UPDATE
所以我发现API拦截器允许将密钥发送到使用DirectX的游戏并且我已经设置了但仍然没有结果......任何能指出我正确方向的人?
SendInput返回什么值?
如果返回 0,则表明发生了某些错误。您可以尝试调用GetLastError来查看输入是否被UIPI阻止,或者尝试使用本地管理员权限运行代码。
您确定procs[0].MainWindowHandle是正确的窗口句柄吗?
最后尝试使用SendMessage将消息直接发送到句柄。
| 归档时间: |
|
| 查看次数: |
2834 次 |
| 最近记录: |