Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 576
  • Last Modified:

turn keyboard lights on & off

turn keyboard lights on & off
i know it is possible (even without setting num lock from your software)
0
markyvt
Asked:
markyvt
  • 6
  • 4
  • 2
  • +3
1 Solution
 
MicrosoftCommented:
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
 
markyvtAuthor Commented:
not working
0
 
MicrosoftCommented:
go here

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

does what you want it to do


cheers

andy
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MicrosoftCommented:
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
 
MicrosoftCommented:
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
 
markyvtAuthor Commented:
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
 
caraf_gCommented:
!? 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
 
iboutchkineCommented:
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
 
caraf_gCommented:
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
 
morgan_peatCommented:
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
 
markyvtAuthor Commented:
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
 
markyvtAuthor Commented:
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
 
daffyduck14milCommented:
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
 
markyvtAuthor Commented:
 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
 
daffyduck14milCommented:
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
 
morgan_peatCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now