I am using keybd_event to set the NUMLOCK on / off.

The keyboard's NUMLOCK state before executing is OFF.
Now I use keybd_event and set the NUMLOCK state to ON.
Then , while trying to retrieve the NUMLOCK keystate through GetKeyState() / GetAsyncKeyState() / GetKeyboardState() , the return value is OFF (ie) 0. But the actual key state is ON.

The GetKeyState() is returning the values of the keystate previous to the calls given to keybd_event. It is not considering the keystate changed due to keybd_event. Could any one help me in this regard.

I want the correct keystate to be retreived even after a keybd_event.

My code is this:
//Keyboard NUMLOCK is OFF
keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);


short s = GetKeyState(VK_NUMLOCK);
BYTE nState1= LOBYTE(s);
BYTE nState2= HIBYTE(s);

//nstate1 is returning 0 instead of 1.