question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PSReadline breaks transparency keyboard shortcuts on Windows 10 console host

See original GitHub issue

The {CTRL} + {SHIFT} + {+/-} keyboard shortcuts for the Windows 10 console host don’t work with PSReadline 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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mklement0commented, Dec 12, 2019

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()
  }
}

~Given that PowerShell doesn’t seem to release references to COM objects, more work may be needed.~ [edited by @daxian-dbw, the referenced issues was closed]

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 <kbd>F9</kbd> and <kbd>F10</kbd>:

# 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('^+{+}')
}
0reactions
daxian-dbwcommented, Apr 6, 2022

Note that <kbd>Ctrl+Shift</kbd> + “mouse wheel scrolling” works with PSReadLine. It’s a workaround for the reported issue. Given that there is nothing much can be done in PSReadLine about this, I will close this issue as external.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows 10 gets a fresh command prompt and lots of ...
Enter "Mark Mode" to move cursor within window. ALT. In conjunction with one of the selection key combinations, begins selection in block mode....
Read more >
I was today years old... : r/PowerShell
You can change the opacity on the fly using Ctrl shift and mouse scroll wheel. ok thats worth way more than just being...
Read more >
Clear screen using Ctrl+L is misbehaving when ...
Ever since upgrading to Windows 10 1809 clearing the screen using Ctrl+L no longer works as expected. I have observed the same behavior...
Read more >
Windows Terminal Troubleshooting
Learn fixes to common obstacles in Windows Terminal.
Read more >
Using PSReadLine key handlers - PowerShell
Keyboard chords are a sequence of one or more keystrokes that are pressed at the same time. For example, the chord Ctrl +...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found