Djibril
May 14th, 1999, 09:25 PM
Could someone tell me how to toggle ON and OFF the Num Lock, Caps Lock & Scroll Lock leds?
Where there is a WISH, there is a WILL.
Where there is a WISH, there is a WILL.
|
Click to See Complete Forum and Search --> : Num Lock, Caps Lock & Scoll Lock Djibril May 14th, 1999, 09:25 PM Could someone tell me how to toggle ON and OFF the Num Lock, Caps Lock & Scroll Lock leds? Where there is a WISH, there is a WILL. ric May 17th, 1999, 08:40 AM Catch them in your overriden function PreTranslateMessage() and what ever you wanna do with them. Something like this: int CMyDialog::PreTranslateMessage(MSG *pMsg) { if(pMsg->message==WM_KEYDOWN) if(pMsg->wParam==VK_NLOCK ||pMsg->message==VK_CLOCK||pMsg->message==VK_SLOCK) { // do your stuff here like return 0; // or whatever you need } return CDialog::PretranslateMessage(pMsg); } Smriti May 25th, 1999, 02:48 AM Hi, You could refer to the KB article number Q127190 in the MSDN. This article tells you exactly how you can acieve this. He asks you to use the keybd_event() to do this. A sample code for toggling the num lock is also given. The sample is as follows: #include <windows.h> void SetNumLock( BOOL bState ) { BYTE keyState[256]; GetKeyboardState((LPBYTE)&keyState); if( (bState && !(keyState[VK_NUMLOCK] & 1)) || (!bState && (keyState[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); } } void main() { SetNumLock( TRUE ); } VK_NUMLOCK is used for num lock. The same code can be modified with VK_CAPITAL & VK_SCROLL for caps lock & scroll lock respectively. Hope this helps. Regards, Smriti Venkatesh codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |