gpt4 book ai didi

c# - SendInput 额外信息/标志

转载 作者:太空宇宙 更新时间:2023-11-03 13:52:05 25 4
gpt4 key购买 nike

我正在尝试将 SendInput api 用于热键应用程序。所以我正在做的是拥有一个全局键钩,当某些组合键命中时,我想发送另一个键。

我的问题是,当我发送模拟 key 时,我的钩子(Hook)会收到该消息,并且我会以递归循环结束。

因此,我尝试使用 ExtraInfo/Flags,但出于某种原因,我设置的值与我在 Hook 中收到的值不同。

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 上设置了什么......当我在我的钩子(Hook)中收到消息时它会被重置:

    private IntPtr KeyStateChangeCallback(int nCode, IntPtr wParam, ref KEYBDINPUT lParam)
{
//lParam.ExtraInfo and lParam.Flags ... is always some mumbo jumbo value or zero...
}

我正在使用低级键盘 Hook “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);
}

有没有人遇到过类似的问题,可以帮我解决一下吗?任何工作代码示例都会很棒 :)

最佳答案

根据documentation , 你应该调用 GetMessageExtraInfo获取 ExtraInfo 字段中的数据。

关于c# - SendInput 额外信息/标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13426822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com