Click here to Skip to main content
Rate this: bad
good
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 at 2-Jul-13 7:47am
   
Is it not simply possible to assign the value of VK_CONTROL to p->vkCode?
novadivlja at 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 at 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
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Afzaal Ahmad Zeeshan 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 27 Aug 2013
Copyright © CodeProject, 1999-2014
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