Locking the system's keyboard

Are there any Windows API functions that locks the system's keyboard?
AgentLimAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
There's no such API. The only way to totally 'control' any keyboard related events is to use a system wide message hook (see 'SetWindowsHookEx()' and 'WH_GETMESSAGE', the hook has to reside in a DLL), e.g.:

LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;
    MSG     msg;

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (   /* ... check whether it's a keyboard message */
            PeekMessage (   &msg,
                            pmsg->hwnd,
                            WM_KEYFIRST,
                            WM_KEYLAST,
                            PM_NOREMOVE
                        )
        )
        {
             
            /* appropriate action, e.g. suppress msg by removing it /*
            PeekMessage (   &msg,
                            pmsg->hwnd,
                            WM_KEYFIRST,
                            WM_KEYLAST,
                            PM_REMOVE
                        );
        }
}

For a detailed description on hooks, see http://msdn.microsoft.com/library/techart/msdn_hooks32.htm


Feel free to ask if you need more information!
0
 
AgentLimAuthor Commented:
Hey Thanx for the info jkr!
0
All Courses

From novice to tech pro — start learning today.