mirror of
https://github.com/peter-tanner/numlock-indicator.git
synced 2024-11-30 14:20:21 +08:00
changed script so icon is always visible, but alternates between
grayscale/color
This commit is contained in:
parent
9700a7dcf8
commit
82f8684973
BIN
icon_off.png
Normal file
BIN
icon_off.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 276 B |
Before Width: | Height: | Size: 276 B After Width: | Height: | Size: 276 B |
17
systray.ps1
17
systray.ps1
|
@ -1,11 +1,14 @@
|
||||||
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
|
[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_ON = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $pwd '\icon_on.png'))).GetHicon()) # Convert my png (bitmap) to an icon
|
||||||
# $ICON = [System.Drawing.Icon]::ExtractAssociatedIcon() # Feel free to use a system icon
|
$ICON_OFF = [System.Drawing.Icon]::FromHandle(([System.Drawing.Bitmap]::FromFile($(Join-Path $pwd '\icon_off.png'))).GetHicon())
|
||||||
|
# $ICON_ON = [System.Drawing.Icon]::ExtractAssociatedIcon() # Feel free to use a system icon
|
||||||
|
# $ICON_OFF = [System.Drawing.Icon]::ExtractAssociatedIcon()
|
||||||
|
|
||||||
function NewTrayIcon(){
|
function NewTrayIcon(){
|
||||||
$TrayIcon = New-Object System.Windows.Forms.NotifyIcon
|
$TrayIcon = New-Object System.Windows.Forms.NotifyIcon
|
||||||
$TrayIcon.Text = "NumLock on"
|
$TrayIcon.Text = "NumLock on"
|
||||||
$TrayIcon.Icon = $ICON
|
$TrayIcon.Icon = If ([console]::numberlock) {$ICON_ON} Else {$ICON_OFF}
|
||||||
|
$TrayIcon.Visible = $true
|
||||||
|
|
||||||
$TrayIcon.Add_Click({ # In case our script stops working, allow user to kill icon so that their system tray isn't cluttered
|
$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.Visible = $false
|
||||||
|
@ -17,13 +20,7 @@ function NewTrayIcon(){
|
||||||
}
|
}
|
||||||
While ($true) {
|
While ($true) {
|
||||||
While ($TrayIcon.Text) {
|
While ($TrayIcon.Text) {
|
||||||
If ([console]::numberlock) {
|
$TrayIcon.Icon = If ([console]::numberlock) {$ICON_ON} Else {$ICON_OFF}
|
||||||
If (!$TrayIcon.Visible) {
|
|
||||||
$TrayIcon.Visible = $true
|
|
||||||
}
|
|
||||||
} ElseIf ($TrayIcon.Visible) {
|
|
||||||
$TrayIcon.Visible = $false
|
|
||||||
}
|
|
||||||
Start-Sleep -Seconds 1 # Set this to whatever polling rate you want.
|
Start-Sleep -Seconds 1 # Set this to whatever polling rate you want.
|
||||||
}
|
}
|
||||||
$TrayIcon = NewTrayIcon
|
$TrayIcon = NewTrayIcon
|
||||||
|
|
Loading…
Reference in New Issue
Block a user