changed script so icon is always visible, but alternates between

grayscale/color
This commit is contained in:
Peter 2021-02-08 13:59:26 +08:00
parent 9700a7dcf8
commit 82f8684973
3 changed files with 7 additions and 10 deletions

BIN
icon_off.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 B

View File

Before

Width:  |  Height:  |  Size: 276 B

After

Width:  |  Height:  |  Size: 276 B

View File

@ -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