PowerShell Pro Tools
Ironman SoftwareGitHub
  • About
  • System Requirements
  • PowerShell Tools Documentation
    • Visual Studio
      • Analysis
      • Debugging
        • Local Debugging
        • Remote Debugging
      • Format Document
      • Go to Definition
      • Packaging in Visual Studio
      • PowerShell 7 Support
      • PowerShell Interactive Window
      • Project System
        • Advanced
        • Debug
        • Build Events
      • Settings
        • General
        • .editorconfig
        • Analysis
        • Diagnostics
      • Tool Windows
      • Refactoring
      • Unit Test Adapter
      • User Interface Design
        • Windows Forms
  • PowerShell Pro Tools Documentation
    • Visual Studio Code
      • Automating Visual Studio Code
      • Code Conversion
      • Debugging
        • Run in New Terminal
        • One-Click Attach
      • Decompiler
      • Diagnostics
      • Enhanced Hover
      • Generating a UI from a function
      • Generate a Tool from a Function
      • Packaging in Visual Studio Code
      • Pin Session
      • PowerShell Explorer
      • Profiler
      • Sign On Save
      • RapidSense
      • Refactoring
      • Rename Symbols
      • Quick Scripts
      • Windows Forms Designer
    • Installers
    • Packaging
      • Package.psd1
      • PowerShell Packager
      • Package Hosts
      • Package as Service
      • Packaging on Linux
      • Packaging on Mac OS X
      • Continuous Integration
      • Anti-Virus
    • PowerShell Module
      • Global Hotkeys
      • Show-PSEditor
      • Show-PSScriptPad
      • Show-TUIDesigner
      • ConvertTo-CSharp
      • ConvertTo-PowerShell
      • Merge-Script
      • Install-PoshProToolsLicense
      • about_MergeScriptConfig
      • Show-WinFormDesigner
    • PowerShell Protect
      • Getting Started
      • Installation
      • Actions
      • Rules
      • Configuration
    • PSCommander
    • PSScriptPad
    • Installation and Licensing
      • Visual Studio Offline Installation
  • Changelog
    • PowerShell Tools for Visual Studio
    • PowerShell Pro Tools for Visual Studio Code
    • PowerShell Packager
    • PSScriptPad
    • PowerShell Pro Tools Module
Powered by GitBook
On this page
  • Defining a Hotkey
  • Passing Variables
  • Accessing Foreground Window and Process Information
  • Retrieving Hotkeys
  • Removing Hotkeys
  1. PowerShell Pro Tools Documentation
  2. PowerShell Module

Global Hotkeys

Global hotkeys for invoking PowerShell with keystrokes.

Global Hotkeys are only supported on Windows.

Global hotkeys allow you to assign hotkeys to PowerShell script blocks. You have access to the current foreground window and process so you can customize your hotkey actions based on what window is open.

Defining a Hotkey

Hotkeys are associated with the current PowerShell window. If you close the window, the hotkeys won't work. You can use the hotkeys anywhere on your desktop as long as PowerShell is open.

You can define hot keys using Set-Hotkey. This cmdlet allows you to specify the action to execute and the modifiers and key to invoke the action.

In the example, pressing Ctrl+B will open notepad.

Set-Hotkey -Action { Start-Process Notepad } -ModifierKeys Ctrl -Key B

Passing Variables

You can pass variables by using the $ArgumentList parameter. These variables will appear in $args variable after the built in foreground and process ID variables.

$Process = "Notepad"
Set-Hotkey -Action { Start-Process $args[2] } -ArgumentList $Process -ModifierKeys Ctrl -Key B

Accessing Foreground Window and Process Information

You can access the foreground window title and process information by using the $args variable. The first argument it the foreground window title and the second argument is the process ID.

This example will write the foreground window title to the console.

Set-Hotkey -Action { Write-Host $args[0] } -ModifierKeys Ctrl -Key B

This example will open another instance of the selected process. The second argument is a process ID.

Set-Hotkey -Action { Start-Process (Get-Process -Id $args[1]).Path } -ModifierKeys Ctrl -Key B

Retrieving Hotkeys

You can use Get-Hotkey to retrieve hotkeys that have been defined.

PS C:\Users\adamr> Get-Hotkey

Action                        ModifierKeys Keys
------                        ------------ ----
 Start-Process $args[1].Path          Ctrl    B

Removing Hotkeys

You can remove hotkeys using Remove-Hotkey.

Get-Hotkey | Remove-Hotkey
PreviousPowerShell ModuleNextShow-PSEditor

Last updated 4 years ago