From 181eb3a89d33a5e17b6bea55f0104d897a04ca1b Mon Sep 17 00:00:00 2001 From: npc-strider Date: Mon, 8 Feb 2021 08:43:03 +0800 Subject: [PATCH] commit --- README.md | 9 +++++++++ icon.png | Bin 0 -> 276 bytes start.sh | 4 ++++ systray.ps1 | 30 ++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 README.md create mode 100644 icon.png create mode 100644 start.sh create mode 100644 systray.ps1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..792ddf4 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# `numlock-indicator` + +This powershell script adds a small indicator to the system tray to indicate when the numlock is enabled. + +Copy files to some directory and run `powershell systray.ps1`. You can also run `start.sh` to ensure that one copy of the script is always active. + +I wrote this because for some reason, my laptop keyboard has no LED indicator for the numlock key (yet they have one for capslock and speakers???) + +Feel free to replace `icon.png` with any bitmap icon if you don't like my terrible pixel art. \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..be6d2f7466c071018d42edb2fcd607e2a90393d3 GIT binary patch literal 276 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$1AIbUf%N|yK!V|(QrQ$B#at5P7ySP}!}U|VK(!2<1s;*b3=Dh+L6~vJ z#O${~!B$Tf#}Etur;`JP8WcEO&iMs5^1Fz3`VqjQUGnvoN;KyzOf+NoB#uV4*3yHwrxZA?o(} zxXyyx964rA8m$M8`A2HVYf14v5ek#`A}T*3eV literal 0 HcmV?d00001 diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..f5ef4f3 --- /dev/null +++ b/start.sh @@ -0,0 +1,4 @@ +# Ensures one copy of the program is always active. Not necessary for operation. +while true; do + powershell './systray.ps1' +done \ No newline at end of file diff --git a/systray.ps1 b/systray.ps1 new file mode 100644 index 0000000..495ba18 --- /dev/null +++ b/systray.ps1 @@ -0,0 +1,30 @@ +[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null +$ICON = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $pwd '\icon.png'))).GetHicon()) # Convert my png (bitmap) to an icon +# $ICON = [System.Drawing.Icon]::ExtractAssociatedIcon() # Feel free to use a system icon + +function NewTrayIcon(){ + $TrayIcon = New-Object System.Windows.Forms.NotifyIcon + $TrayIcon.Text = "NumLock on" + $TrayIcon.Icon = $ICON + + $TrayIcon.Add_Click({ # In case our script stops working, allow user to kill icon so that their system tray isn't cluttered + $TrayIcon.Visible = $false + $TrayIcon.Dispose() + Stop-Process $pid + }) + + return $TrayIcon +} +While ($true) { + While ($TrayIcon.Text) { + If ([console]::numberlock) { + If (!$TrayIcon.Visible) { + $TrayIcon.Visible = $true + } + } ElseIf ($TrayIcon.Visible) { + $TrayIcon.Visible = $false + } + Start-Sleep -Seconds 1 # Set this to whatever polling rate you want. + } + $TrayIcon = NewTrayIcon +} \ No newline at end of file