C# 中的 WH_JOURNALPLAYBACK 挂钩

发布于 2024-12-05 13:02:10 字数 1114 浏览 1 评论 0原文

我正在尝试在 C# 中为“WH_JOURNALPLAYBACK”挂钩创建回调。这是我正确获得回调的代码

private delegate IntPtr JournalPlaybackProc(int nCode, IntPtr wParam, IntPtr lParam);

private static IntPtr JournalPlaybackCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
        if (HC_GETNEXT == nCode && curr < EventMsgs.Count)
        {
            EVENTMSG hookStruct = (EVENTMSG)Marshal.PtrToStructure(lParam, typeof(EVENTMSG));
            EVENTMSG currentMsg = EventMsgs[curr];
            hookStruct.message = currentMsg.message;
            hookStruct.paramL = currentMsg.paramL;
            hookStruct.paramH = currentMsg.paramH;
            hookStruct.hwnd = currentMsg.hwnd;
            hookStruct.time = currentMsg.time;
        }
        if (HC_SKIP == nCode)
        {
            curr++;
        }
        if (curr == EventMsgs.Count)
        {
            UnhookWindowsHookEx(_journalPlaybackProcHookID);
            _journalPlaybackProcHookID = IntPtr.Zero;
        }
        return CallNextHookEx(_journalPlaybackProcHookID, nCode, wParam, lParam);
}

,我想我需要用我的数据修改 lParam 的值来回放事件。我该怎么做?

I am trying to create a callback for "WH_JOURNALPLAYBACK" hook in C#. This is the code

private delegate IntPtr JournalPlaybackProc(int nCode, IntPtr wParam, IntPtr lParam);

private static IntPtr JournalPlaybackCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
        if (HC_GETNEXT == nCode && curr < EventMsgs.Count)
        {
            EVENTMSG hookStruct = (EVENTMSG)Marshal.PtrToStructure(lParam, typeof(EVENTMSG));
            EVENTMSG currentMsg = EventMsgs[curr];
            hookStruct.message = currentMsg.message;
            hookStruct.paramL = currentMsg.paramL;
            hookStruct.paramH = currentMsg.paramH;
            hookStruct.hwnd = currentMsg.hwnd;
            hookStruct.time = currentMsg.time;
        }
        if (HC_SKIP == nCode)
        {
            curr++;
        }
        if (curr == EventMsgs.Count)
        {
            UnhookWindowsHookEx(_journalPlaybackProcHookID);
            _journalPlaybackProcHookID = IntPtr.Zero;
        }
        return CallNextHookEx(_journalPlaybackProcHookID, nCode, wParam, lParam);
}

I get the callback correctly, i suppose i need to modify the value of lParam with my data to playback the events. How do i do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静待花开 2024-12-12 13:02:10

我假设你需要

Marshal.StructureToPtr(hookStruct,lParam,true);

在某个时候写回来。当我运行时它只是挂起。

I assume you need to

Marshal.StructureToPtr(hookStruct,lParam,true);

To write it back at some point. When I run it just hangs though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文