?
Solved

turn keyboard lights on & off

Posted on 2001-06-22
17
Medium Priority
?
540 Views
Last Modified: 2007-12-19
turn keyboard lights on & off
i know it is possible (even without setting num lock from your software)
0
Comment
Question by:markyvt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +3
17 Comments
 
LVL 2

Expert Comment

by:Microsoft
ID: 6217909
try this

Public Const VK_CAPITAL = &H14

Public Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type

Public kbArray As KeyboardBytes

Public Declare Function GetKeyState Lib "user32" _
(ByVal nVirtKey As Long) As Long

Public Declare Function GetKeyboardState Lib "user32" _
(kbArray As KeyboardBytes) As Long

Public Declare Function SetKeyboardState Lib "user32" _
(kbArray As KeyboardBytes) As Long
Code

On a form, add a 3 command buttons (cmdToggle, cmdTurnOn, cmdTurnOff) and a label (Label1). Add the following code to the form:

Private Sub Form_Load()
  If CapsLock() = 1 Then Label1 = "On" Else _
  Label1 = "Off"
End Sub

Private Sub cmdToggle_Click()
  GetKeyboardState kbArray
  kbArray.kbByte(VK_CAPITAL) = _
  IIf(kbArray.kbByte(VK_CAPITAL) = 1, 0, 1)
  SetKeyboardState kbArray

  Label1 = IIf(CapsLock() = 1, "On", "Off")
End Sub

Private Sub cmdTurnOn_Click()
  GetKeyboardState kbArray
  kbArray.kbByte(VK_CAPITAL) = 1
  SetKeyboardState kbArray

  Label1 = IIf(CapsLock() = 1, "On", "Off")
End Sub

Private Sub cmdTurnOff_Click()
  GetKeyboardState kbArray
  kbArray.kbByte(VK_CAPITAL) = 0
  SetKeyboardState kbArray

  Label1 = IIf(CapsLock() = 1, "On", "Off")
End Sub
0
 
LVL 2

Author Comment

by:markyvt
ID: 6217959
not working
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6218005
go here

http://www.downloadsafari.com/Files/emailcheckers/P/POPLight.html

does what you want it to do


cheers

andy
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:Microsoft
ID: 6218055
Private Sub Command1_Click()    Dim i As Integer 'declare the variable
    For i = 1 To 150 'how many times (you can change the 150 to whatever you want)
        SendKeys "{CAPSLOCK}", True 'turn on the capslocks light, then turn it off
        SendKeys "{DOWN}", True 'just to give more time
        SendKeys "{DOWN}", True '^^^^^
        SendKeys "{SCROLLLOCK}", True 'turn on the scroll lock light, turn it off
        SendKeys "{DOWN}", True 'give more time
        SendKeys "{DOWN}", True '^^^^^    Next iEnd Sub
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6218059
Private Sub Command1_Click()
   Dim i As Integer 'declare the variable
    For i = 1 To 150 'how many times (you can change the 150 to whatever you want)
 
       SendKeys "{CAPSLOCK}", True 'turn on the capslocks light, then turn it off

        SendKeys "{DOWN}", True 'just to give more time

        SendKeys "{DOWN}", True '^^^^^

        SendKeys "{SCROLLLOCK}", True 'turn on the scroll lock light, turn it off

        SendKeys "{DOWN}", True 'give more time

        SendKeys "{DOWN}", True '^^^^^  
 Next i
End Sub

sorry first code pasted wrong this should the trick

0
 
LVL 2

Author Comment

by:markyvt
ID: 6218136
This is not what i seek that i already found on planet source code, but i want the lights to turn of/on without putting numlock etc. on.
Like the keyboard plugin for winamp
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 6218195
!? Wait a sec. You want it to turn, say, the "num lock" key on, but without *actually* activating num lock?

That don't make sense.

<confused>
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 6218476
Try this

Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
Private Const VK_NUMLOCK = &H90
Dim ted(0 To 255) As Byte


this sets it on
ted(VK_NUMLOCK) = 1
SetKeyboardState ted(0)

and this off
ted(VK_NUMLOCK) = 0
SetKeyboardState ted(0)


'const for scroll and  caplock
Const VK_SCROLL = &H91
Const VK_CAPITAL = &H14
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 6218491
marky - I have to ask. *why* do you want to be able to toggle the numlock (for example) *light* but not the actual state?

It really doesn't make sense?
0
 
LVL 1

Expert Comment

by:morgan_peat
ID: 6218528
You can set the light status without setting capslock/numlock/scrolllock.
You need to use assembly code tho'.
Have no idea how to do this myself, but you need to send the 'ED' instruction (which is assembler for 'change LED status') to I/O port 60h (the keyboard controller).
Bit 0 sets scroll lock LED status.
Bit 1 sets numlock LED status.
Bit 2 sets capslock LED status.

Good luck - but it's probably best not to even go there...
0
 
LVL 2

Author Comment

by:markyvt
ID: 6220049
ok, you guys want to know what i want with those lights, i see, i'm gonna mod my keyboard with a red, orange, geen led, and then i wanna simulate a traffic light :)
I think that's cool.

I figured out how to set numlock light etc. on but i don't want to change the state.
0
 
LVL 2

Author Comment

by:markyvt
ID: 6224032
You can set the light status without setting capslock/numlock/scrolllock.
You need to use assembly code tho'.
Have no idea how to do this myself, but you need to send the 'ED' instruction (which is assembler for
'change LED status') to I/O port 60h (the keyboard controller).
Bit 0 sets scroll lock LED status.
Bit 1 sets numlock LED status.
Bit 2 sets capslock LED status.

Good luck - but it's probably best not to even go there...

i'm gonna figure out this, in turbo pascal you can use asm code
0
 
LVL 3

Accepted Solution

by:
daffyduck14mil earned 150 total points
ID: 6227273
Just my $0.02...

If you use DirectX DeviceOutput interfaces you can switch led's on the keyboard on and off. Is rather difficult, but then you have no need for assembly.

Grtz.?

D.
0
 
LVL 2

Author Comment

by:markyvt
ID: 6227331
 If you use DirectX DeviceOutput interfaces you can    switch led's on the keyboard on and off. Is rather
difficult, but then you have no need for assembly.  

Grtz.?

Anycode?
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 6227415
Hi,

I would have to cook it up in VB, but I don't have the DirectX installed at work. I can provide the C++ code, wich you can easily convert to VB code (that's why I do anyway). Perhaps someone else can jump in and do that while I work my way down the day and drive home. Anyways, here is the C++ code, enjoy.

void FlashLEDs(void)
    {
    static int         rgiBits[] = { 1, 2, 4, 2 };
    static int         iLooper = 0;
    DWORD              cdod = 3;                  // Number of items
    DIDEVICEOBJECTDATA rgdod[3];
    HRESULT            hres;
 
    // Must clear dwTimeStamp and dwSequence
    ZeroMemory(rgdod, sizeof(rgdod));
 
    rgdod[0].dwOfs = NumLockID;
    rgdod[1].dwOfs = CapsLockID
    rgdod[2].dwOfs = ScrollLockID;
 
    rgdod[0].dwData = (rgiBits[iLooper] & 1) ? 0x80 : 0;
                                           // 1,0,0,0,...
    rgdod[1].dwData = (rgiBits[iLooper] & 2) ? 0x80 : 0;
                                           // 0,1,0,1,...
    rgdod[2].dwData = (rgiBits[iLooper] & 4) ? 0x80 : 0;
                                           // 0,0,1,0,...
 
    iLooper = (iLooper + 1) % ARRAYSIZE(rgiBits); // Loops from 0 to 3
 
    hres = IDirectInputDevice7_SendDeviceData(pdev,
            sizeof(DIDEVICEOBJECTDATA),
            rgdod, &cdod, 0);
    }

Anybody with some exp. can convert it.

grtz.? <-- copyright sign...

D.
0
 
LVL 1

Expert Comment

by:morgan_peat
ID: 6227711
Had a go at this in C++:

void setLEDs(char bits)
{    
     __asm{
         
          mov al, 0EDh          
          out 60h, al          ; Send the 'set LEDs' cmd.(0EDh) to keyboard (port 60h)
     
          mov al, bits     ; Get the 'bits' argument.                    
          out 60h, al          ; Send the LEDs
         
     }
         
}

It compiles OK, but errors on the 'out' command.
Didn't realise this, but writing to ports is a privileged instruction and the code needs to run in kernel mode (like a device driver) rather than user mode.

Seems like it's best to follow the DirectX route....
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question