Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .DESCRIPTION
- Swaps between right-handed mouse buttons and left-handed mouse buttons
- #>
- param ([ValidateSet('Left', 'Right')]$Handed)
- function New-BalloonTip {
- <#
- .SYNOPSIS
- Displays a balloon tip in the lower right corner of the screen.
- .DESCRIPTION
- Displays a balloon tip in the lower right corner of the screen. Icon, title, and text can be customized.
- The icon displayed in the tray can be customized to be one of the standard icons, or, if the -AppIcon switch is used instead, can be the icon used by the application itself.
- .EXAMPLE
- New-BalloonTip -IconType info -Title 'Do not disturb' -Text "I'm busy"
- Description
- -----------
- Creates a balloon tip in the lower right corner.
- .INPUTS
- None. You cannot pipe objects to this script.
- .NOTES
- #Requires -Version 2.0
- .OUTPUTS
- None.
- #>
- [CmdletBinding(DefaultParameterSetName = 'p1')]
- Param (
- [Parameter(Mandatory, Position = 0)][string]$Title,
- [Parameter(Mandatory, Position = 1)][string]$Text,
- [Parameter(ParameterSetName = 'p1')][ValidateSet('Application', 'Asterisk', 'Error', 'Exclamation', 'Hand', 'Information', 'Question', 'Shield', 'Warning', 'WinLogo')][string]$TrayIcon = 'Information',
- [Parameter(ParameterSetName = 'p2')][switch]$AppIcon,
- [Parameter()][ValidateSet('None', 'Info', 'Warning', 'Error')][string]$IconType = 'Info'
- )
- [void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
- $Balloon = New-Object System.Windows.Forms.NotifyIcon
- switch ($PSCmdlet.ParameterSetName) {
- 'p1' {
- $Balloon.Icon = switch ($TrayIcon) {
- 'Application' { [System.Drawing.SystemIcons]::Application }
- 'Asterisk' { [System.Drawing.SystemIcons]::Asterisk }
- 'Error' { [System.Drawing.SystemIcons]::Error }
- 'Exclamation' { [System.Drawing.SystemIcons]::Exclamation }
- 'Hand' { [System.Drawing.SystemIcons]::Hand }
- 'Information' { [System.Drawing.SystemIcons]::Information }
- 'Question' { [System.Drawing.SystemIcons]::Question }
- 'Shield' { [System.Drawing.SystemIcons]::Shield }
- 'Warning' { [System.Drawing.SystemIcons]::Warning }
- 'WinLogo' { [System.Drawing.SystemIcons]::WinLogo }
- }
- }
- 'p2'{
- $path = Get-Process -ID $PID | Select-Object -ExpandProperty Path
- $Balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
- }
- }
- $Balloon.BalloonTipIcon = $IconType
- $Balloon.BalloonTipText = $Text
- $Balloon.BalloonTipTitle = $Title
- $Balloon.Visible = $true
- $Balloon.ShowBalloonTip(10000)
- } # New-BalloonTip
- [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
- $SwapButtons = Add-Type -MemberDefinition @'
- [DllImport("user32.dll")]
- public static extern bool SwapMouseButton(bool swap);
- '@ -Name "NativeMethods" -Namespace "PInvoke" -PassThru
- # Write-Host "Mouse buttons currently swapped?" ([System.Windows.Forms.SystemInformation]::MouseButtonsSwapped)
- if ($PSBoundParameters.ContainsKey('Handed')) {
- if (($Handed -eq 'Left' -and (-not [System.Windows.Forms.SystemInformation]::MouseButtonsSwapped)) -or
- ($Handed -eq 'Right' -and [System.Windows.Forms.SystemInformation]::MouseButtonsSwapped)) {
- [bool]$returnValue = $SwapButtons::SwapMouseButton(!([System.Windows.Forms.SystemInformation]::MouseButtonsSwapped))
- }
- } else {
- [bool]$returnValue = $SwapButtons::SwapMouseButton(!([System.Windows.Forms.SystemInformation]::MouseButtonsSwapped))
- }
- if ([Environment]::UserInteractive) {
- if ([System.Windows.Forms.SystemInformation]::MouseButtonsSwapped) {
- New-BalloonTip -Title 'Left Handed buttons' -Text 'Mouse buttons are now configured for left hand' -TrayIcon Information -IconType Info
- } else {
- New-BalloonTip -Title 'Right Handed buttons' -Text 'Mouse buttons are now configured for right hand' -TrayIcon Information -IconType Info
- }
- } else {
- Write-Output ([System.Windows.Forms.SystemInformation]::MouseButtonsSwapped)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement