全局挂钩(非活动程序)

发布于 2024-12-25 15:21:46 字数 529 浏览 1 评论 0原文

我正在创建一个程序,允许您粘贴文本,但它看起来就像您在粘贴时键入它,粘贴打字机。

我想使用 Ctrl + b 来启动粘贴,但我遇到了热键问题。

我认为我需要的是使用 WH_KEYBOARD_LL 挂钩并包含该 user32 文件,但在添加它和命名空间时通常会出现错误。

我最接近这个:http://thedarkjoker94.cer33.com/?p=111 - 但它似乎不适用于 Ctrlalt 和其他修饰符,即使我使用 KeyData 也是如此。

我需要一种方法来制作即使程序不是活动窗口也能工作的热键。这是 Microsoft Visual C# 2010 中的一个 Windows 窗体应用程序。StackOverlow

主题有很多,但它们已经过时,而且不够完整,无法让我运行某些东西。

I am creating a program that allows you to paste text but it will look like you are typing it as it pastes, Paste Typer.

I am wanting to use Ctrl + b to set off the pasting, but I am having issues with hotkeys.

I think what I need is to use a WH_KEYBOARD_LL hook and include that user32 file but I usually get errors when I add it and the namespace.

I have come closest with this: http://thedarkjoker94.cer33.com/?p=111 - but it doesn't seem to work with Ctrl, alt and other modifiers, even when I used KeyData.

I need a way to make a hotkey that will work even when the program is not the active window. This is a windows forms application in Microsoft Visual C# 2010.

There a rea lot of StackOverlow topics but they are dated and are not complete enough for me to get something running.

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

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

发布评论

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

评论(1

嗳卜坏 2025-01-01 15:21:46

您在谈论 HookManager 吗?

我成功地使用了它,如下所示:

HookManager.KeyDown += new KeyEventHandler(HookManager_KeyDown);

void HookManager_KeyDown(object sender, KeyEventArgs e)
{
    if (Keyboard.IsKeyDown(Keys.LWin)) // Is the Left-Windows Key down and ...
        switch (e.KeyCode)
        {
            case Keys.O: 
                // ...
                e.Handled = true;
                break;
            case Keys.H: 
                // ...
                e.Handled = true;
                break;
        }
}

创建了 Keyboard 类,代码如下:

// Used: http://www.pinvoke.net/default.aspx/user32.getasynckeystate
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Win32.Devices
{
    public class Keyboard
    {
        [DllImport("user32.dll")]
        static extern ushort GetAsyncKeyState(Keys vKey);

        public static bool IsKeyDown(Keys key)
        {
            return 0 != (GetAsyncKeyState(key) & 0x8000);
        }
    }
}

Are you talking about the HookManager?

I use it successfully like this:

HookManager.KeyDown += new KeyEventHandler(HookManager_KeyDown);

and

void HookManager_KeyDown(object sender, KeyEventArgs e)
{
    if (Keyboard.IsKeyDown(Keys.LWin)) // Is the Left-Windows Key down and ...
        switch (e.KeyCode)
        {
            case Keys.O: 
                // ...
                e.Handled = true;
                break;
            case Keys.H: 
                // ...
                e.Handled = true;
                break;
        }
}

I created the Keyboard class here is the code:

// Used: http://www.pinvoke.net/default.aspx/user32.getasynckeystate
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Win32.Devices
{
    public class Keyboard
    {
        [DllImport("user32.dll")]
        static extern ushort GetAsyncKeyState(Keys vKey);

        public static bool IsKeyDown(Keys key)
        {
            return 0 != (GetAsyncKeyState(key) & 0x8000);
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文