Seems that tunring on and off the numlock key is not so simple as desired.
There is not a native CVI function for that, but looking in the SDK and the knowledge base, I arranged this piece of software that works on a Win98 machine:
void ToggleNumLock (void)
{
short state;
int err;
BYTE ks[256];
// Method 1: should work on Win98 but it doesn't
/*
err = GetKeyboardState (ks);
ks[90] = !ks[90];
err = SetKeyboardState (ks);
*/
// Method 2: should work on WinNT or Win2K
/*
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // function options
ULONG_PTR dwExtraInfo // additional keystroke data
);
*/
//err = GetKeyboardState (ks
);
/* bstate holds the desired state for the button
if( (bState && !(ks[VK_NUMLOCK] & 1)) ||
(!bState && (ks[VK_NUMLOCK] & 1)) )
{
*/
/*
// Simulate a key press
keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
// Simulate a key release
keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
*/
//}
// Method 3: actually works on Win98
err = GetKeyboardState (ks);
state = GetKeyState (VK_NUMLOCK);
ks[VK_NUMLOCK] = !state;
err = SetKeyboardState (ks);
return;
}
For reference, look at these two Microsoft articles in the MSDN:
Q177674 HOWTO: Toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK Keys
Q127190 : HOWTO: Toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK Keys
Hope this helps
Roberto