[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: light up my keyboard
For those interested, the following C code gives a crude example of flashing
the lights on a keyboard in windows - it actually sets the keys rather than
just changing the lights.
It works OK on my Win2K machine. I'll leave the conversion to matlab for
someone
else!!!!!!
My understanding of windows is that to access the lights you have to use
different methods
for different versions of the OS - WinNT needs the device driver kit.
Another example for NT can be found at
http://www.codeguru.com/system/NTKbdLites.shtml
Richard J Baker
------------------------------------------------------------
Human Communication and Deafness
School of Education
University of Manchester
Oxford Road
Manchester M13 9PL
Tel. +44 (0)161 275 3388
Fax. +44 (0)161 275 3373
------------------------------------------------------------
//--------------------------------------------------------------------------
------------------------
// the following code flashes the three keyboard lights
// in windows - this is example is for a DOS box at present
//
// note also, that it actually sets the key itself rather than
// just change the lights
//
// the basic code was adapted from that at:
// http://www.codeguru.com/mfc/comments/28296.shtml
//
// Richard J Baker, University of Manchester
#include <windows.h>
#include <mmsystem.h>
#include <time.h>
void SetNumLock(BOOL);
void SetCapsLock(BOOL);
void SetScrollLock(BOOL);
void delay(int);
main()
{
int i,j;
for(i=0;i<10;i++){
SetNumLock(1);
SetCapsLock(1);
SetScrollLock(1);
delay(1);
SetNumLock(0);
SetCapsLock(0);
SetScrollLock(0);
}
}
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 SetCapsLock( BOOL bState )
{
BYTE keyState[256];
GetKeyboardState((LPBYTE)&keyState);
if ( (bState && !(keyState[VK_CAPITAL] & 1)) || (!bState &&
(keyState[VK_CAPITAL] & 1)) )
{
// Simulate a key press
keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
// Simulate a key release
keybd_event( VK_CAPITAL, 0x45, KEYEVENTF_EXTENDEDKEY |
KEYEVENTF_KEYUP, 0);
}
}
void SetScrollLock( BOOL bState )
{
BYTE keyState[256];
GetKeyboardState((LPBYTE)&keyState);
if ( (bState && !(keyState[VK_SCROLL] & 1)) || (!bState &&
(keyState[VK_SCROLL] & 1)) )
{
// Simulate a key press
keybd_event( VK_SCROLL, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0 );
// Simulate a key release
keybd_event( VK_SCROLL, 0x45, KEYEVENTF_EXTENDEDKEY |
KEYEVENTF_KEYUP, 0);
}
}
void delay(int secs){
time_t start,t;
start = time(NULL);
while (time(NULL) < (start + secs));
}