【发布时间】:2017-03-30 19:19:55
【问题描述】:
所以我遇到了一个问题,我正在尝试向游戏发送密钥,我在 SetForegroundWindow 的帮助下将游戏置于前台,并且我正在使用 SendInputs API 将密钥发送到游戏。
如果我专注于另一个应用程序,则密钥将发送到该应用程序,但只要我专注于我希望将密钥发送到的应用程序,它们就不会出现在那里。
我正在努力节省一些时间来为我的公会招募公会成员,并且我正在尝试发送游戏密钥。
[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)));
其余代码: https://pastebin.com/RUm7A311
更新
所以我找到了允许将密钥发送到使用 DirectX 的游戏的 API 拦截器,我已经设置了它但仍然没有结果.. 谁能指出我正确的方向?
【问题讨论】:
-
您可以尝试让 AutoHotKey 与游戏一起使用。我曾经这样做过,但我花了一段时间才成功,因为某些方法由于各种原因显然不适用于某些游戏。也许这些与您的程序无法正常工作的原因相同。它可以帮助您缩小问题范围:autohotkey.com/docs/commands/Send.htm
-
尝试使用sendkeys.Send方法
-
已经试过那个方法了。 @itay_421
-
你试过keybd_event吗?例如:stackoverflow.com/questions/14395377/…msdn:msdn.microsoft.com/en-us/library/windows/desktop/…