Разработка, производство и продажа радиоэлектронной аппаратуры
|
Требуется программист в Зеленограде - обработка данных с датчиков; ColdFire; 40 тыс.
e-mail: jobsmp@pochta.ru
|
PSS ID Number: Q127190
Authored 14-Mar-1995 Last modified 25-May-1995
The information in this article applies to:
- Microsoft Win32 Software Development Kit (SDK), versions 3.5, 3.51,
and 4.0
SUMMARY
The documentation for SetKeyboardState() correctly says that you cannot
use this API to toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK keys.
You can use keybd_event() to toggle the NUM LOCK, CAPS LOCK, and SCROLL
LOCK keys.
MORE INFORMATION
The following sample program turns the NUM LOCK light on if it is off. The
SetNumLock function defined here simulates pressing the NUM LOCK key, using
keybd_event() with a virtual key of VK_NUMLOCK. It takes a boolean value
that indicates whether the light should be turned off (FALSE) or on (TRUE).
The same technique can be used for the CAPS LOCK key (VK_CAPITAL) and the
SCROLL LOCK key (VK_SCROLL).
Sample Code
-----------
/* Compile options needed:
*/
#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 );
}
Additional reference words: 3.50 4.00 95
KBCategory: kbprg kbcode
KBSubcategory: UsrInp
Составить ответ | Вернуться на конференцию
Ответы