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.
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.
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.
This example will open another instance of the selected process. The second argument is a process ID.
Retrieving Hotkeys
You can use Get-Hotkey
to retrieve hotkeys that have been defined.
Removing Hotkeys
You can remove hotkeys using Remove-Hotkey
.
Last updated