Author Topic: Reversing Caps Lock LED Functionality  (Read 5393 times)

0 Members and 1 Guest are viewing this topic.

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Reversing Caps Lock LED Functionality
« on: Thu, 22 October 2015, 20:21:40 »
I've tried searching the forms as well as google to see if there is a way to do anything like this. I assume it's something I could do by switching the way something soldered but am not 100% sure and would prefer to do it without having to do any solder work, however if that is the only way I'll do it.

Basically what I'm trying to do for ascetic purposes is make it so that when Caps Lock is turned off the caps lock LED is on and when it's on the LED is off. It's always bothered me on all of my keyboards that caps lock is the only key that I don't have a led on however I've normally just dealt with it, so hopefully there's some easy trick/program to do this!

Otherwise please let me know what sort of soldering I will need to do if it's possible that way!

Thanks!
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #1 on: Thu, 22 October 2015, 20:57:16 »
The way I see it, the most simple way to do it would be by replacing the controller on your keyboard. I'm not 100% certain that Easy AVR allows you to invert the leds, so make sure that it does(or nicely ask metalliqaz to implement that feature). If your thinking about modifying your HHKB then this thread might be of interest to you.

Doing it with pure hardware mods would be much more messy, but if I had to do it that way I'd probably hardwire the caps lock led(with a resistor) to the USB connector, and use the caps lock led pads on the pcb as a source of switching signal used by a relay or a transistor or something along those lines. And even if it worked I'm not sure you'd be able to cleanly fit it all inside the enclosure again.

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Re: Reversing Caps Lock LED Functionality
« Reply #2 on: Thu, 22 October 2015, 21:06:49 »
Thanks for the info I'll have to look into Easy AVR, I'm actually trying to do this on a Leeku 1800 PCB and there's a pretty good key mapper with the PCB however it doesn't have any sort of caps lock led inversion. Sadly it looks like the Easy AVR doesn't have any support for the Leeku :(
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline SamirD

  • * Esteemed Elder
  • Posts: 1508
  • Location: HSV and SFO
  • on Buckling Springs since '88
    • http://www.huntsvillecarscene.com
Re: Reversing Caps Lock LED Functionality
« Reply #3 on: Thu, 22 October 2015, 21:57:00 »
Back in the day, there were old DOS programs to manipulate your keyboard leds.  I'm not sure if they'd work today, but it might be worth checking out.

Offline SamirD

  • * Esteemed Elder
  • Posts: 1508
  • Location: HSV and SFO
  • on Buckling Springs since '88
    • http://www.huntsvillecarscene.com
Re: Reversing Caps Lock LED Functionality
« Reply #4 on: Thu, 22 October 2015, 22:30:15 »
Here's some software code that reverses the scroll lock that might be able to be used to affect caps lock by someone that knows how to code (I don't):
https://gist.github.com/haroldhues/e9190c0259a7b96a7a7a

Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #5 on: Fri, 23 October 2015, 07:03:11 »
Here's some software code that reverses the scroll lock that might be able to be used to affect caps lock by someone that knows how to code (I don't):
https://gist.github.com/haroldhues/e9190c0259a7b96a7a7a


That's a script for AutoHotkey, and something like that will work, but only on Windows(wich is the only OS supported by AHK), and only the computer it's installed on. I'm not sure that's a solution that would work for op.

Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #6 on: Fri, 23 October 2015, 07:36:03 »
I've modified that AutoHotKey script to invert the capslock indicator led, just in case I was wrong and it'll actually work for op(or anyone else for that matter).

Code: [Select]
#SingleInstance force
 ; I have a backlit keyboard that used the ScrollLock led to determine when the
 ; lights are on, this script basically reverses the state so that ScrollLock is
 ; off when the light is on.
~NumLock::
~CapsLock::
~ScrollLock::
  Sleep, 10 ; improve reliability of setting LED state sometimes
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off")
  Else
    KeyboardLED(4,"on")
Return

/*

    Keyboard LED control for AutoHotkey_L
        http://www.autohotkey.com/forum/viewtopic.php?p=468000#468000

    KeyboardLED(LEDvalue, "Cmd", Kbd)
        LEDvalue  - ScrollLock=1, NumLock=2, CapsLock=4
        Cmd       - on/off/switch
        Kbd       - index of keyboard (probably 0 or 2)

*/

KeyboardLED(LEDvalue, Cmd, Kbd=0)
{
  SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
  h_device:=NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
 
  If Cmd= switch  ;switches every LED according to LEDvalue
   KeyLED:= LEDvalue
  If Cmd= on  ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
   KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
  If Cmd= off  ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
    {
    LEDvalue:= LEDvalue ^ 7
    KeyLED:= LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
    }
 
  success := DllCall( "DeviceIoControl"
              ,  "ptr", h_device
              , "uint", CTL_CODE( 0x0000000b     ; FILE_DEVICE_KEYBOARD
                        , 2
                        , 0             ; METHOD_BUFFERED
                        , 0  )          ; FILE_ANY_ACCESS
              , "int*", KeyLED << 16
              , "uint", 4
              ,  "ptr", 0
              , "uint", 0
              ,  "ptr*", output_actual
              ,  "ptr", 0 )
 
  NtCloseFile(h_device)
  return success
}

CTL_CODE( p_device_type, p_function, p_method, p_access )
{
  Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
}


NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs)
{
  VarSetCapacity(objattrib,6*A_PtrSize,0)
  VarSetCapacity(io,2*A_PtrSize,0)
  VarSetCapacity(pus,2*A_PtrSize)
  DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
  NumPut(6*A_PtrSize,objattrib,0)
  NumPut(&pus,objattrib,2*A_PtrSize)
  status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib
                  ,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist
                  ,"UInt",flags,"ptr",0,"UInt",0, "UInt")
  return % fh
}

NtCloseFile(handle)
{
  return DllCall("ntdll\ZwClose","ptr",handle)
}


SetUnicodeStr(ByRef out, str_)
{
  VarSetCapacity(out,2*StrPut(str_,"utf-16"))
  StrPut(str_,&out,"utf-16")
}
« Last Edit: Fri, 23 October 2015, 07:43:07 by dr_habu »

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Re: Reversing Caps Lock LED Functionality
« Reply #7 on: Fri, 23 October 2015, 07:54:22 »
Nice I'll give that a shot and let you know if it works out for me :D
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Re: Reversing Caps Lock LED Functionality
« Reply #8 on: Fri, 23 October 2015, 08:04:04 »
Code: [Select]
Specifically: KeyboardLED﴾4,"off"﴿

Line#
005: Return
008: Sleep,10
009: if ﴾GetKeyState﴾"CapsLock", "T"﴿﴿
‐‐‐> 010: KeyboardLED﴾4,"off"﴿
011: Else
012: KeyboardLED﴾4,"on"﴿a
013: Return
014: Exit

The program will exit.

Also one of the things I read online was doing some registry editing, which I did, however now the keymapper that came with my keyboard is unable to make any changes to the caps lock/ctrl key even though I undid my changes if anyone has any clue what could cause this it would be appreciated.
« Last Edit: Fri, 23 October 2015, 08:07:54 by daviswalkers »
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline SamirD

  • * Esteemed Elder
  • Posts: 1508
  • Location: HSV and SFO
  • on Buckling Springs since '88
    • http://www.huntsvillecarscene.com
Re: Reversing Caps Lock LED Functionality
« Reply #9 on: Fri, 23 October 2015, 08:30:15 »
I've modified that AutoHotKey script to invert the capslock indicator led, just in case I was wrong and it'll actually work for op(or anyone else for that matter).

Code: [Select]
#SingleInstance force
 ; I have a backlit keyboard that used the ScrollLock led to determine when the
 ; lights are on, this script basically reverses the state so that ScrollLock is
 ; off when the light is on.
~NumLock::
~CapsLock::
~ScrollLock::
  Sleep, 10 ; improve reliability of setting LED state sometimes
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off")
  Else
    KeyboardLED(4,"on")
Return

/*

    Keyboard LED control for AutoHotkey_L
        http://www.autohotkey.com/forum/viewtopic.php?p=468000#468000

    KeyboardLED(LEDvalue, "Cmd", Kbd)
        LEDvalue  - ScrollLock=1, NumLock=2, CapsLock=4
        Cmd       - on/off/switch
        Kbd       - index of keyboard (probably 0 or 2)

*/

KeyboardLED(LEDvalue, Cmd, Kbd=0)
{
  SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
  h_device:=NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
 
  If Cmd= switch  ;switches every LED according to LEDvalue
   KeyLED:= LEDvalue
  If Cmd= on  ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
   KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
  If Cmd= off  ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
    {
    LEDvalue:= LEDvalue ^ 7
    KeyLED:= LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
    }
 
  success := DllCall( "DeviceIoControl"
              ,  "ptr", h_device
              , "uint", CTL_CODE( 0x0000000b     ; FILE_DEVICE_KEYBOARD
                        , 2
                        , 0             ; METHOD_BUFFERED
                        , 0  )          ; FILE_ANY_ACCESS
              , "int*", KeyLED << 16
              , "uint", 4
              ,  "ptr", 0
              , "uint", 0
              ,  "ptr*", output_actual
              ,  "ptr", 0 )
 
  NtCloseFile(h_device)
  return success
}

CTL_CODE( p_device_type, p_function, p_method, p_access )
{
  Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
}


NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs)
{
  VarSetCapacity(objattrib,6*A_PtrSize,0)
  VarSetCapacity(io,2*A_PtrSize,0)
  VarSetCapacity(pus,2*A_PtrSize)
  DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
  NumPut(6*A_PtrSize,objattrib,0)
  NumPut(&pus,objattrib,2*A_PtrSize)
  status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib
                  ,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist
                  ,"UInt",flags,"ptr",0,"UInt",0, "UInt")
  return % fh
}

NtCloseFile(handle)
{
  return DllCall("ntdll\ZwClose","ptr",handle)
}


SetUnicodeStr(ByRef out, str_)
{
  VarSetCapacity(out,2*StrPut(str_,"utf-16"))
  StrPut(str_,&out,"utf-16")
}
Wow, super!  I'm sure there will be use for this by others too.  :thumb:


Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #10 on: Fri, 23 October 2015, 20:47:23 »
Code: [Select]
Specifically: KeyboardLED﴾4,"off"﴿

Line#
005: Return
008: Sleep,10
009: if ﴾GetKeyState﴾"CapsLock", "T"﴿﴿
‐‐‐> 010: KeyboardLED﴾4,"off"﴿
011: Else
012: KeyboardLED﴾4,"on"﴿a
013: Return
014: Exit

The program will exit.

Also one of the things I read online was doing some registry editing, which I did, however now the keymapper that came with my keyboard is unable to make any changes to the caps lock/ctrl key even though I undid my changes if anyone has any clue what could cause this it would be appreciated.


Have you tried reinstalling that keymapper?
Also I didn't quite get what you were trying to say in that code block, but I suspect that you have a problem with the script. Could you please elaborate?

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Re: Reversing Caps Lock LED Functionality
« Reply #11 on: Fri, 23 October 2015, 21:29:23 »
Yeah I even used it on a different computer which makes no sense considering the only thing that changed before it stopped working was a changed some registry information...

And I'm not sure what to elaborate on, I made a text file put your code in it saved it as .ahk or whatever it is and when I run it that code pops up
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #12 on: Sat, 24 October 2015, 02:29:45 »
Well, it looks like you didn't copy all the code. There's a scrollbar on that code box in my post. Make sure you copy everything and it should work.
« Last Edit: Sat, 24 October 2015, 02:41:16 by dr_habu »

Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #13 on: Sat, 24 October 2015, 16:04:06 »
I've updated the code slightly. In the initial version you had to toggle capslock at least once for the led to get inverted - now it'll invert the led automatically after startup. The other change is that the script now restores the default led behaviour before exiting.

The full script is 114 lines long. Please make sure you copy all of it!

Code: [Select]
#SingleInstance force
OnExit("ExitFunc")
SetTimer, InitialSetup, -100

 ; I have a backlit keyboard that used the ScrollLock led to determine when the
 ; lights are on, this script basically reverses the state so that ScrollLock is
 ; off when the light is on.

~NumLock::
~CapsLock::
~ScrollLock::
  Sleep, 10 ; improve reliability of setting LED state sometimes
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off")
  Else {
    KeyboardLED(4,"on")
    }
Return

InitialSetup:
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off")
  Else {
    KeyboardLED(4,"on")
    }
Return

ExitFunc(ExitReason, ExitCode)
{
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"on")
  Else {
    KeyboardLED(4,"off")
    } 
    ExitApp
}

/*

    Keyboard LED control for AutoHotkey_L
        http://www.autohotkey.com/forum/viewtopic.php?p=468000#468000

    KeyboardLED(LEDvalue, "Cmd", Kbd)
        LEDvalue  - ScrollLock=1, NumLock=2, CapsLock=4
        Cmd       - on/off/switch
        Kbd       - index of keyboard (probably 0 or 2)

*/

KeyboardLED(LEDvalue, Cmd, Kbd=0)
{
  SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
  h_device:=NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
 
  If Cmd= switch  ;switches every LED according to LEDvalue
   KeyLED:= LEDvalue
  If Cmd= on  ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
   KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
  If Cmd= off  ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
    {
    LEDvalue:= LEDvalue ^ 7
    KeyLED:= LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
    }
 
  success := DllCall( "DeviceIoControl"
              ,  "ptr", h_device
              , "uint", CTL_CODE( 0x0000000b     ; FILE_DEVICE_KEYBOARD
                        , 2
                        , 0             ; METHOD_BUFFERED
                        , 0  )          ; FILE_ANY_ACCESS
              , "int*", KeyLED << 16
              , "uint", 4
              ,  "ptr", 0
              , "uint", 0
              ,  "ptr*", output_actual
              ,  "ptr", 0 )
 
  NtCloseFile(h_device)
  return success
}

CTL_CODE( p_device_type, p_function, p_method, p_access )
{
  Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
}


NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs)
{
  VarSetCapacity(objattrib,6*A_PtrSize,0)
  VarSetCapacity(io,2*A_PtrSize,0)
  VarSetCapacity(pus,2*A_PtrSize)
  DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
  NumPut(6*A_PtrSize,objattrib,0)
  NumPut(&pus,objattrib,2*A_PtrSize)
  status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib
                  ,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist
                  ,"UInt",flags,"ptr",0,"UInt",0, "UInt")
  return % fh
}

NtCloseFile(handle)
{
  return DllCall("ntdll\ZwClose","ptr",handle)
}


SetUnicodeStr(ByRef out, str_)
{
  VarSetCapacity(out,2*StrPut(str_,"utf-16"))
  StrPut(str_,&out,"utf-16")
}
« Last Edit: Mon, 26 October 2015, 19:13:52 by dr_habu »

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Re: Reversing Caps Lock LED Functionality
« Reply #14 on: Tue, 27 October 2015, 22:03:19 »
I've updated the code slightly. In the initial version you had to toggle capslock at least once for the led to get inverted - now it'll invert the led automatically after startup. The other change is that the script now restores the default led behaviour before exiting.

The full script is 114 lines long. Please make sure you copy all of it!

Code: [Select]
#SingleInstance force
OnExit("ExitFunc")
SetTimer, InitialSetup, -100

 ; I have a backlit keyboard that used the ScrollLock led to determine when the
 ; lights are on, this script basically reverses the state so that ScrollLock is
 ; off when the light is on.

~NumLock::
~CapsLock::
~ScrollLock::
  Sleep, 10 ; improve reliability of setting LED state sometimes
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off")
  Else {
    KeyboardLED(4,"on")
    }
Return

InitialSetup:
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off")
  Else {
    KeyboardLED(4,"on")
    }
Return

ExitFunc(ExitReason, ExitCode)
{
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"on")
  Else {
    KeyboardLED(4,"off")
    } 
    ExitApp
}

/*

    Keyboard LED control for AutoHotkey_L
        http://www.autohotkey.com/forum/viewtopic.php?p=468000#468000

    KeyboardLED(LEDvalue, "Cmd", Kbd)
        LEDvalue  - ScrollLock=1, NumLock=2, CapsLock=4
        Cmd       - on/off/switch
        Kbd       - index of keyboard (probably 0 or 2)

*/

KeyboardLED(LEDvalue, Cmd, Kbd=0)
{
  SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
  h_device:=NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
 
  If Cmd= switch  ;switches every LED according to LEDvalue
   KeyLED:= LEDvalue
  If Cmd= on  ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
   KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
  If Cmd= off  ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
    {
    LEDvalue:= LEDvalue ^ 7
    KeyLED:= LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
    }
 
  success := DllCall( "DeviceIoControl"
              ,  "ptr", h_device
              , "uint", CTL_CODE( 0x0000000b     ; FILE_DEVICE_KEYBOARD
                        , 2
                        , 0             ; METHOD_BUFFERED
                        , 0  )          ; FILE_ANY_ACCESS
              , "int*", KeyLED << 16
              , "uint", 4
              ,  "ptr", 0
              , "uint", 0
              ,  "ptr*", output_actual
              ,  "ptr", 0 )
 
  NtCloseFile(h_device)
  return success
}

CTL_CODE( p_device_type, p_function, p_method, p_access )
{
  Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
}


NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs)
{
  VarSetCapacity(objattrib,6*A_PtrSize,0)
  VarSetCapacity(io,2*A_PtrSize,0)
  VarSetCapacity(pus,2*A_PtrSize)
  DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
  NumPut(6*A_PtrSize,objattrib,0)
  NumPut(&pus,objattrib,2*A_PtrSize)
  status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib
                  ,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist
                  ,"UInt",flags,"ptr",0,"UInt",0, "UInt")
  return % fh
}

NtCloseFile(handle)
{
  return DllCall("ntdll\ZwClose","ptr",handle)
}


SetUnicodeStr(ByRef out, str_)
{
  VarSetCapacity(out,2*StrPut(str_,"utf-16"))
  StrPut(str_,&out,"utf-16")
}

Ah I didn't see any scroll on mine sorry! Thanks for all your help I'll give this a shot at work tomorrow and let you know how it goes! Really appreciate all your help :)!
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Re: Reversing Caps Lock LED Functionality
« Reply #15 on: Wed, 28 October 2015, 07:41:21 »
So that works to some extent, and here might be the issue, I'm plugging the keyboard into a laptop, the LED on the laptop for caps lock is on but the keyboard remains off.
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #16 on: Wed, 28 October 2015, 10:15:53 »
So that works to some extent, and here might be the issue, I'm plugging the keyboard into a laptop, the LED on the laptop for caps lock is on but the keyboard remains off.

Is the indicator led on the keyboard connected to your laptop off, or is the keyboard connected to the laptop off(as in not working at all)?
I'll assume that you meant the former.

It didn't even occur to me that you might be using more than one keyboard(the built in laptop keyboard is counted as the first keyboard by the OS).

He's another revision of my script. This time you'll have to change the numeric value on line #8. I've set it to 0 as a default so it'll work just like the previous version if you don't change it, but it should work with your laptop if you change it to something else. I've tested it with my thinkpad laptop and a spare keyboard, and the script started controlling the indicator leds on the spare keyboard when I set that value to 3. It might be something else in your case. Try experimenting with it until it works for you.

Code: [Select]
#SingleInstance force
OnExit("ExitFunc")
SetTimer, InitialSetup, -100

 ; kbd_id - the index number of the keyboard that we want to control.
 ;Probably 0 or 2 for your main keyboard, might be something else for any additional keyboards

global kbd_id := 0

 ; I have a backlit keyboard that used the ScrollLock led to determine when the
 ; lights are on, this script basically reverses the state so that ScrollLock is
 ; off when the light is on.

~NumLock::
~CapsLock::
~ScrollLock::
  Sleep, 10 ; improve reliability of setting LED state sometimes
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off",kbd_id)
  Else {
    KeyboardLED(4,"on",kbd_id)
    }
Return

InitialSetup:
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off",kbd_id)
  Else {
    KeyboardLED(4,"on",kbd_id)
    }
Return

ExitFunc(ExitReason, ExitCode)
{
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"on",kbd_id)
  Else {
    KeyboardLED(4,"off",kbd_id)
    } 
    ExitApp
}

/*

    Keyboard LED control for AutoHotkey_L
        http://www.autohotkey.com/forum/viewtopic.php?p=468000#468000

    KeyboardLED(LEDvalue, "Cmd", Kbd)
        LEDvalue  - ScrollLock=1, NumLock=2, CapsLock=4
        Cmd       - on/off/switch
        Kbd       - index of keyboard (probably 0 or 2)

*/

KeyboardLED(LEDvalue, Cmd, Kbd=0)
{
  SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
  h_device:=NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
 
  If Cmd= switch  ;switches every LED according to LEDvalue
   KeyLED:= LEDvalue
  If Cmd= on  ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
   KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
  If Cmd= off  ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
    {
    LEDvalue:= LEDvalue ^ 7
    KeyLED:= LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
    }
 
  success := DllCall( "DeviceIoControl"
              ,  "ptr", h_device
              , "uint", CTL_CODE( 0x0000000b     ; FILE_DEVICE_KEYBOARD
                        , 2
                        , 0             ; METHOD_BUFFERED
                        , 0  )          ; FILE_ANY_ACCESS
              , "int*", KeyLED << 16
              , "uint", 4
              ,  "ptr", 0
              , "uint", 0
              ,  "ptr*", output_actual
              ,  "ptr", 0 )
 
  NtCloseFile(h_device)
  return success
}

CTL_CODE( p_device_type, p_function, p_method, p_access )
{
  Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
}


NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs)
{
  VarSetCapacity(objattrib,6*A_PtrSize,0)
  VarSetCapacity(io,2*A_PtrSize,0)
  VarSetCapacity(pus,2*A_PtrSize)
  DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
  NumPut(6*A_PtrSize,objattrib,0)
  NumPut(&pus,objattrib,2*A_PtrSize)
  status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib
                  ,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist
                  ,"UInt",flags,"ptr",0,"UInt",0, "UInt")
  return % fh
}

NtCloseFile(handle)
{
  return DllCall("ntdll\ZwClose","ptr",handle)
}


SetUnicodeStr(ByRef out, str_)
{
  VarSetCapacity(out,2*StrPut(str_,"utf-16"))
  StrPut(str_,&out,"utf-16")
}
« Last Edit: Wed, 28 October 2015, 11:09:52 by dr_habu »

Offline SamirD

  • * Esteemed Elder
  • Posts: 1508
  • Location: HSV and SFO
  • on Buckling Springs since '88
    • http://www.huntsvillecarscene.com
Re: Reversing Caps Lock LED Functionality
« Reply #17 on: Wed, 28 October 2015, 11:05:46 »
Have I mentioned how much I love the helpfulness of this place and the people in it?  :thumb:

Amazing stuff!

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Re: Reversing Caps Lock LED Functionality
« Reply #18 on: Wed, 28 October 2015, 19:31:13 »
So that works to some extent, and here might be the issue, I'm plugging the keyboard into a laptop, the LED on the laptop for caps lock is on but the keyboard remains off.

Is the indicator led on the keyboard connected to your laptop off, or is the keyboard connected to the laptop off(as in not working at all)?
I'll assume that you meant the former.

It didn't even occur to me that you might be using more than one keyboard(the built in laptop keyboard is counted as the first keyboard by the OS).

He's another revision of my script. This time you'll have to change the numeric value on line #8. I've set it to 0 as a default so it'll work just like the previous version if you don't change it, but it should work with your laptop if you change it to something else. I've tested it with my thinkpad laptop and a spare keyboard, and the script started controlling the indicator leds on the spare keyboard when I set that value to 3. It might be something else in your case. Try experimenting with it until it works for you.

Code: [Select]
#SingleInstance force
OnExit("ExitFunc")
SetTimer, InitialSetup, -100

 ; kbd_id - the index number of the keyboard that we want to control.
 ;Probably 0 or 2 for your main keyboard, might be something else for any additional keyboards

global kbd_id := 0

 ; I have a backlit keyboard that used the ScrollLock led to determine when the
 ; lights are on, this script basically reverses the state so that ScrollLock is
 ; off when the light is on.

~NumLock::
~CapsLock::
~ScrollLock::
  Sleep, 10 ; improve reliability of setting LED state sometimes
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off",kbd_id)
  Else {
    KeyboardLED(4,"on",kbd_id)
    }
Return

InitialSetup:
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"off",kbd_id)
  Else {
    KeyboardLED(4,"on",kbd_id)
    }
Return

ExitFunc(ExitReason, ExitCode)
{
  If (GetKeyState("CapsLock", "T"))
    KeyboardLED(4,"on",kbd_id)
  Else {
    KeyboardLED(4,"off",kbd_id)
    } 
    ExitApp
}

/*

    Keyboard LED control for AutoHotkey_L
        http://www.autohotkey.com/forum/viewtopic.php?p=468000#468000

    KeyboardLED(LEDvalue, "Cmd", Kbd)
        LEDvalue  - ScrollLock=1, NumLock=2, CapsLock=4
        Cmd       - on/off/switch
        Kbd       - index of keyboard (probably 0 or 2)

*/

KeyboardLED(LEDvalue, Cmd, Kbd=0)
{
  SetUnicodeStr(fn,"\Device\KeyBoardClass" Kbd)
  h_device:=NtCreateFile(fn,0+0x00000100+0x00000080+0x00100000,1,1,0x00000040+0x00000020,0)
 
  If Cmd= switch  ;switches every LED according to LEDvalue
   KeyLED:= LEDvalue
  If Cmd= on  ;forces all choosen LED's to ON (LEDvalue= 0 ->LED's according to keystate)
   KeyLED:= LEDvalue | (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
  If Cmd= off  ;forces all choosen LED's to OFF (LEDvalue= 0 ->LED's according to keystate)
    {
    LEDvalue:= LEDvalue ^ 7
    KeyLED:= LEDvalue & (GetKeyState("ScrollLock", "T") + 2*GetKeyState("NumLock", "T") + 4*GetKeyState("CapsLock", "T"))
    }
 
  success := DllCall( "DeviceIoControl"
              ,  "ptr", h_device
              , "uint", CTL_CODE( 0x0000000b     ; FILE_DEVICE_KEYBOARD
                        , 2
                        , 0             ; METHOD_BUFFERED
                        , 0  )          ; FILE_ANY_ACCESS
              , "int*", KeyLED << 16
              , "uint", 4
              ,  "ptr", 0
              , "uint", 0
              ,  "ptr*", output_actual
              ,  "ptr", 0 )
 
  NtCloseFile(h_device)
  return success
}

CTL_CODE( p_device_type, p_function, p_method, p_access )
{
  Return, ( p_device_type << 16 ) | ( p_access << 14 ) | ( p_function << 2 ) | p_method
}


NtCreateFile(ByRef wfilename,desiredaccess,sharemode,createdist,flags,fattribs)
{
  VarSetCapacity(objattrib,6*A_PtrSize,0)
  VarSetCapacity(io,2*A_PtrSize,0)
  VarSetCapacity(pus,2*A_PtrSize)
  DllCall("ntdll\RtlInitUnicodeString","ptr",&pus,"ptr",&wfilename)
  NumPut(6*A_PtrSize,objattrib,0)
  NumPut(&pus,objattrib,2*A_PtrSize)
  status:=DllCall("ntdll\ZwCreateFile","ptr*",fh,"UInt",desiredaccess,"ptr",&objattrib
                  ,"ptr",&io,"ptr",0,"UInt",fattribs,"UInt",sharemode,"UInt",createdist
                  ,"UInt",flags,"ptr",0,"UInt",0, "UInt")
  return % fh
}

NtCloseFile(handle)
{
  return DllCall("ntdll\ZwClose","ptr",handle)
}


SetUnicodeStr(ByRef out, str_)
{
  VarSetCapacity(out,2*StrPut(str_,"utf-16"))
  StrPut(str_,&out,"utf-16")
}
[/quote


So just try changing the 0 around until the LED on the keyboard (not the laptop keyboard) turns on then?

Also yes the keyboard works fine it's just that the laptop light is on and not the keyboard's light (refering to caps LED)

Finally as stated above thank you so much for all your help and information you've been a great help!
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #19 on: Wed, 28 October 2015, 19:46:11 »
You're welcome. I registered on GH just last week. I decided to come here because I had some questions that I couldn't find answers for, so I started the thread with my questions, and in the meantime I tried helping other people. I didn't want to just take from the community without giving anything back - that wouldn't be fair.

But yeah just change the 0 to something else, just to make it easier here are the steps to make it work:

  • increment the numerical value(0 by default) on line 8
  • save the script
  • run the script
  • Check if it works they way you want
  • If it doesn't - exit the script(right click on the ahk icon in the tray menu and select "exit") and go back to the first step

« Last Edit: Wed, 28 October 2015, 19:50:29 by dr_habu »

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Re: Reversing Caps Lock LED Functionality
« Reply #20 on: Wed, 28 October 2015, 20:38:00 »
Yeah makes sense! Hopefully you get answers to your questions soon if you haven't already!

And I have quite a lot of use with AHK I use it for a bunch of games I play to add easier to use macro's since I play with a 60% at home, just never got into the actual writing of scripts for the most part, after seeing this it may be something I need to look into considering I'm an application developer shouldn't be too hard to pick up :D
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #21 on: Wed, 28 October 2015, 20:55:28 »
For the most part AHK is easy. It's getting a bit more complicated once you start accessing built in windows functions.
I'm not an expert on AHK by any stretch, I just did some programming in various languages and modifying that scroll lock script seemed pretty easy.

Hopefully this time it'll work for you.

Offline SamirD

  • * Esteemed Elder
  • Posts: 1508
  • Location: HSV and SFO
  • on Buckling Springs since '88
    • http://www.huntsvillecarscene.com
Re: Reversing Caps Lock LED Functionality
« Reply #22 on: Wed, 28 October 2015, 22:54:42 »
Since you've been so helpful in this thread, I found all your threads to see if I could help you and I just happened to have some recent experience that may help you find your ultimate board.  :thumb:

Offline daviswalkers

  • Thread Starter
  • Posts: 296
  • Location: Columbus, Ohio
  • HHKB Amature 2
    • Graphic Design Portfolio
Re: Reversing Caps Lock LED Functionality
« Reply #23 on: Thu, 29 October 2015, 07:24:40 »
For the most part AHK is easy. It's getting a bit more complicated once you start accessing built in windows functions.
I'm not an expert on AHK by any stretch, I just did some programming in various languages and modifying that scroll lock script seemed pretty easy.

Hopefully this time it'll work for you.

It works :D thank you so much!
      
Compact-SQ |          VE.A
 65g Zealios    |      78g Zealios

Offline dr_habu

  • Posts: 46
Re: Reversing Caps Lock LED Functionality
« Reply #24 on: Thu, 29 October 2015, 07:48:30 »
It works :D thank you so much!

Awesome! ;D

I'm glad I could help!


Since you've been so helpful in this thread, I found all your threads to see if I could help you and I just happened to have some recent experience that may help you find your ultimate board.  :thumb:

Thank you very much! I really appreciate it!