Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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);
}


How to remap LALT to LCTRL? Can you give me some idea to solve that?
Posted
Comments
chaau 21-Aug-13 20:46pm    
I think you need to use SetKeyboardState http://msdn.microsoft.com/en-us/library/windows/desktop/ms646314(v=vs.85).aspx
novadivlja 23-Aug-13 5:58am    
Can you be more specific, what to do with SetKeyboardState, where to put it, what will get if i put those function in code? ... i need idea for solving problem.

1 solution

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
 
Comments
novadivlja 30-Aug-13 3:38am    
Thnx for replay i tested but it seems that it doesn't work, can you post full code from application?
novadivlja 30-Aug-13 3:49am    
I can't copy and paste with Alt & c and Alt & v, how can defeat that?

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