commit 181eb3a89d33a5e17b6bea55f0104d897a04ca1b Author: npc-strider Date: Mon Feb 8 08:43:03 2021 +0800 commit 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 0000000..be6d2f7 Binary files /dev/null and b/icon.png differ 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