Detect-KeyInput.ps1

something exciting

Some information about the exciting thing

Table of contents generated with markdown-toc


Script

# Add required assemblies
Add-Type -AssemblyName WindowsBase
Add-Type -AssemblyName PresentationCore

# Pause to be able to press and hold a key
Start-Sleep -Seconds 2

# Key list
$Nokey = [System.Windows.Input.Key]::None
$key1 = [System.Windows.Input.Key]::LeftCtrl
$key2 = [System.Windows.Input.Key]::LeftShift

# Key presses
$isNokey = $Nokey
$isCtrl = [System.Windows.Input.Keyboard]::IsKeyDown($key1)
$isShift = [System.Windows.Input.Keyboard]::IsKeyDown($key2)

# If no key is pressed, launch User Home Profile
if ($isNokey -eq 'None') {
    & (Join-Path $PSScriptRoot "/PersonalProfiles/HomePowerShell_profile.ps1")
}

# If LeftCtrl key is pressed, connect to Office365
elseif ($isCtrl) {
    & (Join-Path $PSScriptRoot "/PersonalProfiles/Connect-Office365Services.ps1")
}

# If LeftShift key is pressed, start PowerShell without a Profile
elseif ($isShift) {
    Start-Process "pwsh.exe" -ArgumentList  "-noprofile" -NoNewWindow
}

Back to Top


Download

Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top