Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,

I need to lock keyboard for my project. How can I do this? It's need to work all Windows systems(Win 7 and Win8 for start)..

I'm waiting for answer. Thanks for answers. Have a good day..
Posted
Updated 14-Jun-15 2:57am
Comments
LLLLGGGG 14-Jun-15 9:16am    
There are a lot of solution on the intermet. Have you checked them? What have you tried so far?
Umut Comlekcioglu 14-Jun-15 10:11am    
Yes I'm check too many solution but I can't found what I want. Finally I found that one,

LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam;
if (p->vkCode == VK_LMENU) // VK_LMENU = ALT key
{
switch (wParam){

case WM_SYSKEYDOWN :{ // use SYSKEYDOWN
cout << "Key down" << endl;

keybd_event(VK_LCONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | 0, 0 );
break;
}
case WM_KEYUP: // use regular keyup
{
cout << "Key up" << endl;

keybd_event( VK_LCONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
return 1;

break;
}
default:
wParam = WM_SYSKEYDOWN; // if you do not specify it changes back to alt
break;
}
return 1;
}
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}

but I want to ask them too.
LLLLGGGG 14-Jun-15 12:18pm    
If it works add it as a solution in order to make other developers understand that the question is closed.
Afzaal Ahmad Zeeshan 14-Jun-15 10:31am    
Just do not handle the input at all.

1 solution

C++
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT* p = (KBDLLHOOKSTRUCT*) lParam;
if (p->vkCode == VK_LMENU) // VK_LMENU = ALT key
{
switch (wParam){

case WM_SYSKEYDOWN :{ // use SYSKEYDOWN
cout << "Key down" << endl;

keybd_event(VK_LCONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | 0, 0 );
break;
}
case WM_KEYUP: // use regular keyup
{
cout << "Key up" << endl;

keybd_event( VK_LCONTROL, 0x1D, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
return 1;

break;
}
default:
wParam = WM_SYSKEYDOWN; // if you do not specify it changes back to alt
break;
}
return 1;
}
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}


It's work for handle key input. Everyone can use this..
 
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