How do you register a custom Win+V hotkey on Windows 8?

与世无争的帅哥 提交于 2019-12-10 10:29:02

问题


It was possible to register the Win+V hotkey on versions of Windows prior to Windows 8. An example application using this combination is PureText.

With the Windows 8 Release Preview I've noticed that Windows 8 has taken control of a lot of hotkeys involving Windows key, but Win+V doesn't appear to be used. The following code will allow me to register a hotkey for 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;
}

If I modify it to register just Win+V then it'll fail to register:

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

Is there a way to force registration of the Windows+V hotkey? I assume that there might be a way to do this with Win32 API hooking but it has been a while since I've looked at that. More easily supported options for achieving this would be appreciated.


回答1:


The RegisterHotKey function has always reserved the Windows key for the system. The documentation even indicates such:

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.

You should choose a different [set of] modifier key[s] when registering your own non-system hotkey.

Besides, as others have mentioned, the

+V keyboard shortcut is already in use. And RegisterHotKey fails when you try to register a hot key that is already registered.

Lots of Win32 functions set an error code that indicates what exactly went wrong when they don't work. If the documentation indicates as much, you can call the GetLastError function to determine what that error code was. That will give you a lot more information to help in debugging the problem.




回答2:


Here is the full list of Windows 8 keyboard shortcuts in pdf or xps. Win+V is already in use; it cycles through notifications. Sticking with Win+CTRL+V is probably your best option.




回答3:


Use PlainTexter... it uses a global keyboard hook. {Works on my machine}

http://www.elijahg.com/plaintexter



来源:https://stackoverflow.com/questions/11767458/how-do-you-register-a-custom-winv-hotkey-on-windows-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!