本文介绍了如何使用LowLevelKeyboardProc重新映射C ++中的键盘键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要重新映射一些键,例如LALT,但我只是将其禁用,因此用于禁用"LALT"的代码如下所示:

I need to remap some of keys like LALT but i just disable it so code for disable "LALT" look like this:

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode == HC_ACTION)
    {
        KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam;
        if (p->vkCode == VK_LMENU) return 1;
    }
    return CallNextHookEx(hHook, nCode, wParam, lParam);
}


因此,我尝试将LALT重新映射为LCTRL并使用"keybd_event"和"SendMessageA"之类的功能,但一无所获.


So i try to remap LALT to LCTRL and use function like "keybd_event" and "SendMessageA" but didn''t get nothing.

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode == HC_ACTION)
    {
        KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam;
        if (p->vkCode == VK_LMENU)
        {
            keybd_event(VK_CONTROL, 0, 0, 0);
            // or use this is sameSendMessageA(0, WM_KEYUP, VK_CONTROL, 0);
        }
    }
    return CallNextHookEx(hHook, nCode, wParam, lParam);
}


推荐答案

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode == HC_ACTION)
    {
        KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam;
        if (p->vkCode == VK_LMENU)
        {
            if (wParam == WM_KEYDOWN)

                keybd_event(VK_LCONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | 0, 0 );

            else if (wParam == WM_KEYUP)

                keybd_event( VK_LCONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);


            return 1;
        }
    }
    return CallNextHookEx(hHook, nCode, wParam, lParam);
}





这些行将解决您的问题,如果您按LALT键,则它将用作LCTRL,即,按下LCTRL键,如果释放LALT,则将释放LCTRL.





These lines will solve your problem if you press LALT then it will act as LCTRL i.e. LCTRL key will be depressed and if you release LALT, LCTRL will be released.


这篇关于如何使用LowLevelKeyboardProc重新映射C ++中的键盘键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-17 15:17