Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I need to remap some of keys like LALT but i just disable it so code for disable "LALT" look like this:
C++
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);
}

So i try to remap LALT to LCTRL and use function like "keybd_event" and "SendMessageA" but didn't get nothing.
C++
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);
}

How to remap LALT to LCTRL?
Posted
Comments
Bernhard Hiller 2-Jul-13 7:47am    
Is it not simply possible to assign the value of VK_CONTROL to p->vkCode?
novadivlja 2-Jul-13 9:45am    
i just tried and it want send anything, i think that need to use GetKeystate for determine in what state is LCTRL and if is DOWN send up else reverse...
The_Inventor 6-Jul-13 3:30am    
I think you need to create, initialize, set and / or modify HHOOK hHook; before you can use:

return CallNextHookEx(hHook, nCode, wParam, lParam); returning uninitialized variables results in "nothing"

1 solution

SQL
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);
}




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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900