mirror of
https://github.com/peter-tanner/numlock-indicator.git
synced 2024-11-30 14:20:21 +08:00
commit
This commit is contained in:
commit
181eb3a89d
9
README.md
Normal file
9
README.md
Normal file
|
@ -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.
|
4
start.sh
Normal file
4
start.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
# Ensures one copy of the program is always active. Not necessary for operation.
|
||||
while true; do
|
||||
powershell './systray.ps1'
|
||||
done
|
30
systray.ps1
Normal file
30
systray.ps1
Normal file
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user