winapi - 如何在 Windows 8 上注册自定义 Win+V 热键?

标签 winapi windows-8 hotkeys registerhotkey

可以在 Windows 8 之前的 Windows 版本上注册 Win+V 热键。使用此组合的示例应用程序是 PureText

通过 Windows 8 Release Preview,我注意到 Windows 8 已经控制了很多涉及 Windows 键的热键,但 Win+V 似乎没有被使用。以下代码将允许我注册 Win+CTRL+V 的热键:

#include <Windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
    if (RegisterHotKey(
        NULL,
        1,
        MOD_WIN | MOD_NOREPEAT | MOD_CONTROL,
        0x56))  // 0x56 is 'v'
    {
        _tprintf(_T("Hotkey 'CTRL+WIN+V' registered, using MOD_NOREPEAT flag\n"));
    }

    MSG msg = {0};
    while (GetMessage(&msg, NULL, 0, 0) != 0)
    {
        if (msg.message == WM_HOTKEY)
        {
            _tprintf(_T("WM_HOTKEY received\n"));            
        }
    } 

    return 0;
}

如果我将其修改为仅注册Win+V,则会注册失败:

if (RegisterHotKey(
    NULL,
    1,
    MOD_WIN | MOD_NOREPEAT,
    0x56))  // 0x56 is 'v'
{
    _tprintf(_T("Hotkey 'WIN+V' registered, using MOD_NOREPEAT flag\n"));
}

有没有办法强制注册 Windows+V 热键?我认为可能有一种方法可以通过 Win32 API Hook 来做到这一点,但自从我研究它以来已经有一段时间了。更容易支持实现这一目标的选项将不胜感激。

最佳答案

RegisterHotKey函数始终为系统保留Windows key 。 The documentation甚至表明这样:

MOD_WIN 0x0008
Either WINDOWS key was held down. These keys are labeled with the Windows logo. Keyboard shortcuts that involve the WINDOWS key are reserved for use by the operating system.

在注册您自己的非系统热键时,您应该选择不同的[一组]修饰键。

此外,正如其他人提到的, Windows key +V 键盘快捷键已在使用中。当您尝试注册已注册的热键时,RegisterHotKey 会失败。

许多 Win32 函数都会设置一个错误代码,指示它们在不工作时到底出了什么问题。如果文档说明了这么多,您可以调用 GetLastError function以确定该错误代码是什么。这将为您提供更多信息来帮助调试问题。

关于winapi - 如何在 Windows 8 上注册自定义 Win+V 热键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11767458/

相关文章:

keyboard-shortcuts - 转到 Atom 编辑器中的最后一行

refactoring - 如何使用 ReSharper 导航到右括号?

linux - 我可以在 Ubuntu 中向 Qt 应用程序添加全局快捷方式 Hook 吗?

c++ - 无法将参数从 'const char[20]' 转换为 'LPCWSTR'

c++ - 创建 Win32 工具栏的好教程吗?

c - 设置 MinGW 在 WINAPI 中创建 OpenGL 上下文?

javascript - 如何在 Windows 应用商店应用程序中以 JSON 格式文件保存到磁盘(使用 WinJS)?

delphi - Delphi 和 C++ WinAPI 函数的地址在不应该不同的情况下不同

python-2.7 - 使用 Windows Visual Studio 2013 的 Boost 1.55 Python,链接错误

c# - 您应该在 Windows 8 应用程序的哪个位置编码 'privacy policy' ?