我正在尝试将 SendInput api 用于热键应用程序。所以我正在做的是拥有一个全局键钩,当一些键组合命中时,我想发送另一个键。
我的问题是,当我发送模拟密钥时,我的钩子会收到该消息,最终会出现递归循环。
因此,我尝试使用 ExtraInfo / Flags,但由于某种原因,我设置的值与我在挂钩中收到的值不同。
var down = new INPUT();
down.Type = (UInt32)InputType.Keyboard;
down.Data.Keyboard = new KEYBDINPUT();
down.Data.Keyboard.KeyCode = (UInt16)keyCode;
down.Data.Keyboard.Scan = 0;
down.Data.Keyboard.Flags = 0; //doesn't matter whatever I set here... never gets back to my hook
down.Data.Keyboard.Time = 0;
down.Data.Keyboard.ExtraInfo = IntPtr.Zero; //doesn't matter whatever I set here... never gets back to my hook
无论我在 ExtraInfo / Flags 上设置什么......当我在我的钩子中收到消息时它都会重置:
private IntPtr KeyStateChangeCallback(int nCode, IntPtr wParam, ref KEYBDINPUT lParam)
{
//lParam.ExtraInfo and lParam.Flags ... is always some mumbo jumbo value or zero...
}
我正在使用低级键盘挂钩,“WH_KEYBOARD_LL”,设置如下:
proc = KeyStateChangeCallback;
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
hookID = NativeMethods.SetWindowsHookEx(WH_KEYBOARD_LL, proc, NativeMethods.GetModuleHandle(curModule.ModuleName), 0);
}
其他人有类似的问题,可以帮助我吗?任何工作代码示例都会很棒:)