New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PSReadline breaks transparency keyboard shortcuts on Windows 10 console host #280
Comments
There's no good fix for this issue that I'm aware of. conhost can't take over those key bindings because applications may use them for their own purposes, but conhost doesn't provide any api for an application (like PSReadline) to access that functionality. This affects some other new and useful key bindings as well, e.g. Ctrl+m for selection. The conhost team is aware of the issue. I'll leave this open because there is a hack that I think might work - basically using something like SendKeys and then calling the cooked mode readline to get conhost to process the key. That might work for single keys, but I'm not sure that would work with Ctrl+m because I don't know how to get control back after the selection has been completed. |
Here are workarounds for most of the currently unsupported shortcuts: Set-PSReadlineKeyHandler Alt+F4 -ScriptBlock {
(New-Object -ComObject WScript.Shell).SendKeys('%{F4}')
}
Set-PSReadlineKeyHandler Ctrl+f -ScriptBlock {
(New-Object -ComObject WScript.Shell).SendKeys('^f')
}
Set-PSReadlineKeyHandler Ctrl+m -ScriptBlock {
(New-Object -ComObject WScript.Shell).SendKeys('^m')
}
Set-PSReadlineKeyHandler F11 -ScriptBlock {
(New-Object -ComObject WScript.Shell).SendKeys('{F11}')
}
Set-PSReadlineKeyHandler Ctrl+a -ScriptBlock {
$length = 0; $line = ''
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref] $line, [ref] $null)
[Microsoft.PowerShell.PSConsoleReadLine]::GetSelectionState([ref] $null, [ref] $length)
if ($length -eq $line.Length) { # whole line already selected -> select whole scroll-back buffer
(New-Object -ComObject WScript.Shell).SendKeys('^a')
} else { # select whole line
[Microsoft.PowerShell.PSConsoleReadLine]::SelectAll()
}
}
The transparency-increasing/decreasing shortcuts cannot be emulated this way, because the modifier-key status is lost after the initial keypress, so that auto-repeating invocation for gradual adjustment doesn't work, making the emulation too cumbersome to use. However, you can at least get the functionality via different shortcut keys, as long as they don't involve modifiers; the following definitions demonstrate that with F9 and F10: # Decrease transparency
# !! Only works with auto-repeating invocations with a shortcut *without modifiers*,
# !! because the modifier status is lost after the first .SendKeys() call.
# !! Therefore, the original shortcut, Ctrl+_ (Ctrl+Shift+Minus) cannot be used.
Set-PSReadlineKeyHandler F9 -ScriptBlock {
(New-Object -ComObject WScript.Shell).SendKeys('^+-')
}
# Increase transparency
# !! Only works with auto-repeating invocations with a shortcut *without modifiers*,
# !! because the modifier status is lost after the first .SendKeys() call.
# !! Therefore, the original shortcut, Ctrl++ (Ctrl+Shift+Plus) cannot be used.
Set-PSReadlineKeyHandler F10 -ScriptBlock {
(New-Object -ComObject WScript.Shell).SendKeys('^+{+}')
} |
Should we bind these by default on Windows? |
Using |
@lzybkr that's true since |
Note that Ctrl+Shift + "mouse wheel scrolling" works with PSReadLine. It's a workaround for the reported issue. |
The
{CTRL} + {SHIFT} + {+/-}
keyboard shortcuts for the Windows 10 console host don't work withPSReadline
imported into the PowerShell session. Removing the module fixes the shortcuts, as a temporary workaround.Cheers,
Trevor Sullivan
Microsoft MVP PowerShell
http://trevorsullivan.net
http://twitter.com/pcgeek86
The text was updated successfully, but these errors were encountered: