Click here to Skip to main content
12,079,202 members (46,707 online)
Rate this:
 
Please Sign up or sign in to vote.
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);
}
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?
Posted 1-Jul-13 22:41pm
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160212.1 | Last Updated 27 Aug 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100