ThinkPads & The Keyboard Backlight

Introduction

What I love about an Asus laptop and Macbook is the backlight is on while typing. Whichever method of choice to make that possible – it didn’t matter – it just happens. This doesn’t happen on a ThinkPad though. Why? Not too sure. Is it that was done intentionally to keep the backlight from burning out? Possible and plausible, but does that really matter? Yes. No one wants to spend the money in replacing the backlight of a keyboard. Should it prevent being able to use the backlight? No of course not. It’s a function of the device. Well, no one wants to manually turn the backlight on all the time or burn out the backlight. To top it off, make it so the ThinkPad backlight isn’t on while an external keyboard is connected.

Recap of the problems we’re solving:

  1. The backlight keyboard comes on when the computer is unlocked and when an external USB device is not plugged in.
  2. The backlight keyboard goes off when the computer is locked, idle for 1 minute or more and an external device is plugged in.

Finding A Solution

Instead of reinventing the wheel, we need to setoff on an adventure in finding if anything like this exists. Well, it looks like there is! It appears that Jonas Hendrickx has made a post about this very issue of turning the keyboard on at boot - How to turn on keyboard backlight at boot for ThinkPads? - which means we can use this as a baseline for our custom script.

That’s just awesome! Makes life a little bit easier. Following the guide we’ll make sure the proper dependencies are installed: Lenovo System Interface Foundation

Once that is installed, let’s move onto using our custom script from dudetechitout auto-keyboard-backlight

Let's save that in the Document's directory under the 'scripts' folder (Win+R > %USERPROFILE%\Documents > Return > CTRL+Shift+N > "scripts") as auto-keyboard-backlight.ps1.

Now let's do a little bit of scheduling that'll cover the use of an external keyboard, boot, sleep and wakeup, hibernation and wakeup, idle, lock and unlock using the Task Scheduler in Windows:

To schedule the boot, unlock and external keyboard with Task Scheduler:

  1. Click 'Create Task'.
  2. Choose 'Run whether user is logged in or not'. (Make use sure user that executes script has permissions to run on this machine.)
  3. Add a trigger 'At startup'.
  4. Add a trigger 'On workstation unlock'.
  5. Add a trigger 'On an event' if you want to support detection of USB keyboard (unfortunately no convenient way of detecting USB removal/insertion - have to use Audio as a tick). Make sure 'Microsoft-Windows-Audio/Informational' is enabled by going to Start > Event Viewer > Applications and Services Logs > Microsoft > Windows > Audio > Informational and Right click 'Informational' and select 'Enable Log' before doing this.
    • Log: 'Microsoft-Windows-Audio/Informational'
    • Source: 'Audio'
    • EventID: '155'
  6. Add a trigger 'On an event' if you want to support sleep and hibernation. You'll need to find the EventID in Windows Event Manager.
    • Log: 'System'
    • Source: 'Power-Troubleshooter'
    • EventID: 1
  7. Add an action with 'Program/script' location set to 'C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe' and parameters '-File path\to\script\auto-keyboard-backlight.ps1'

To schedule with Task Scheduler for idle:

  1. Click 'Create Task'.
  2. Choose 'Run whether user is logged in or not'. (Make use sure user that executes script has permissions to run on this machine.)
  3. Add a trigger 'On idle'.
  4. Go to the Conditions tab and select 'Start the task only if the computer is idle for:' to '1 minute' with 'Wait for idle for:' 'Do not wait', uncheck 'Stop if the computer ceases to be idle'.
  5. Add an action with 'Program/script' location set to 'C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe' and parameters '-File path\to\script\auto-keyboard-backlight.ps1 true'

To schedule with Task Scheduler for lock:

  1. Click 'Create Task'.
  2. Choose 'Run whether user is logged in or not'. (Make use sure user that executes script has permissions to run on this machine.)
  3. Add a trigger 'On workstation lock'.
  4. Add an action with 'Program/script' location set to 'C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe' and parameters '-File path\to\script\auto-keyboard-backlight.ps1 true'

Be sure that all theses tasks run whether the laptop is on AC or not by unchecking the box 'Start the task only if the computer is on AC power' under 'Conditions'.

Now that the script has been placed in the correct directory and the tasks are all scheduled, next is to make the script actually work and that is done by signing it.

Signing Our Solution

Open a powershell terminal with administrator privilages, enter the command below and press 'y':

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

We now need to make the certificate in an ordinary/non-elevated PowerShell console by entering:

New-SelfSignedCertificate -DnsName dudecodeitout -CertStoreLocation Cert:\CurrentUser\My\ -Type Codesigning

Now open the Certificate Management Console: certmgr.msc > Personal > Certificates. Select and Copy your dudecodeitout to the clipboard and paste this certificate into Trusted Root Certification Authority (or you can import this certificate to the computer’s Trusted Root CA).

Time to sign the PowerShell script! You can sign the PowerShell script using the command below:

Set-AuthenticodeSignature -FilePath C:\Users\yourusername\Documents\scripts\auto-keyboard-backlight.ps1 -Certificate (Get-ChildItem -Path Cert:\CurrentUser\My\ -CodeSigningCert)

Opening the script 'auto-keyboard-backlight.ps1' you should now see '# SIG # Begin signature block' and that means it was a success!

Why Audio Logs?

It was quite difficult in finding a solution in checking whether a USB device had been unplugged or plugged in. Which can be possibly blamed on Event Viewer aging with the development of Windows; not getting enough TLC from Microsoft. Rather than continue wasting time in finding a viable solution for this, it was best to enable the audio logs and use that, as each time a device is unplugged or plugged back in an audio clip is played, which can be attached to, and the script changed to accommodate such a solution. Plus, it opens the doors of enabling various other features.

Conclusion

That's all there is to it! Upon locking, unlocking, boot, ideling and plugging or unplugging an external keyboard the backlight will react appropriately.