本文介绍了如何在C ++中使用控件重新映射Alt?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我尝试将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);
}
如何将LALT重新映射到LCTRL?您可以给我一些解决方案吗?
How to remap LALT to LCTRL? Can you give me some idea to solve that?
推荐答案
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.
这篇关于如何在C ++中使用控件重新映射Alt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!