Click to See Complete Forum and Search --> : NumLock Status


sarambur
May 28th, 2002, 06:05 AM
How can I set the NumLock status to ON in a C++ program?
Is there any System Call to do it?

Thanks.

vikramn
May 28th, 2002, 06:56 AM
This could help in VC
http://www.codeguru.com/misc/controlling_lock_keys.shtml

I also remember doing this using Assembly language in C via some keyboard interrrupt. Don't remember which interrupt is for keyboard.

Cheers
V

Paul McKenzie
May 28th, 2002, 01:50 PM
Originally posted by sarambur
How can I set the NumLock status to ON in a C++ program?
Is there any System Call to do it?

Thanks. In standard C++, there is no function call to get the status of the numlock. You have to rely on what your operating system provides, and each operating system will use different methods.

Regards,

Paul McKenzie

vikramn
May 29th, 2002, 03:59 AM
Yeaa.. In C++ there is no function that allows you to set/get the status of NUMLOCK/CAPSLOCK key.

So whatever the OS is , in C++ you can set/get the status of these keys using BIOS calls.

You will have to find a function under Int 9 (Keyboard BIOS interrupt) which allows you to set/get values of these keys.

Cheers
V

sarambur
May 29th, 2002, 08:24 AM
int ReqdNumLockState = 0x0001;


if( (GetKeyState( VK_NUMLOCK ) & 0x0001) != ReqdNumLockState )
{
//Ponemos el NumLock a ON, para que se pueda escribir con el numpad directamente.
keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
keybd_event( VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );
}


finally I have used this piece of code.
I havent tested it yet, and I will post if it works or not in about 5 minutes (for anyone who wants to know, of course).

Paul McKenzie
May 29th, 2002, 10:35 AM
You also need to post what Windows OS this worked on. This forum is not a Windows-only forum.

Regards,

Paul McKenzie