PSReadLine icon indicating copy to clipboard operation
PSReadLine copied to clipboard

'Alt' prints '@' when it's remapped to an unassigned key code (vkE8 or vkFF)

Open eugenesvk opened this issue 4 years ago • 4 comments

I'm using Autohotkey to suppress the annoying menukey functionality of the Alt key (selecting menu items on a single press of Alt). However, in PowerShell with PSReadline enabled it prints @ symbols instead of printing nothing (this bug report is a copy of https://github.com/PowerShell/PowerShell/issues/14357 where I learned that the culprit is PSReadline (I don't get any @ symbols when loading Powershell without this module))

Environment

PS version: 7.2.0-preview.1
PSReadline version: 2.2.0-beta1
os: 10.0.19041.320 (WinBuild.160101.0800)
PS file version: 7.2.0.0
HostName: ConsoleHost
BufferWidth: 127
BufferHeight: 30000

Steps to reproduce

Assign the following Autohotkey (this is for v2, in v1 omit the ' symbols) mapping to the Alt key:

~Alt::Send '{Blind}{vkE8}'

This sends an unassigned key signal that should do nothing, but has the benefit of masking the menukey functionality (vkFF has no mapping, but still bugs Powershell).

Press the Alt key

Expected behavior

Nothing should be printed, just like nothing is printed in all the other apps (cmd.exe console, old system powershell.exe console or any other GUI app)


Actual behavior

I get an @ symbol printed instead

@

eugenesvk avatar Dec 09 '20 19:12 eugenesvk

It's likely the [System.Console]::ReadKey() call in .NET returns something when you press Alt after your mapping. Can you check what ReadKey() returns? Just run [System.Console]::ReadKey() in PowerShell, and then press Alt.

daxian-dbw avatar Dec 10 '20 18:12 daxian-dbw

@daxian-dbw doesn't seem to be the case, the command you suggested simply prints blank KeyChars with correct virtual key code and a modifier

↓AHK mapping | pwsh Output → KeyChar Key Modifiers
                             ------- --- ---------
~Alt::Send '{Blind}{vkFF}' →         255  Alt
~Alt::Send '{Blind}{vkE8}' →         232  Alt
~Alt::Send '{Blind}{vk07}' →         7    Alt

eugenesvk avatar Dec 10 '20 18:12 eugenesvk

You can solve this from AHK side. Just dump the buggy code and try this. Read more.

*LAlt::SetKeyDelay(-1), Send("{LAlt down}{Shift}"), KeyWait("LAlt")
~*LAlt up::SetKeyDelay(-1), Send("{Blind}{LAlt up}")

*RAlt::SetKeyDelay(-1), Send("{RAlt down}{Shift}"), KeyWait("RAlt")
~*RAlt up::SetKeyDelay(-1), Send("{Blind}{RAlt up}")

necaran avatar Mar 23 '24 19:03 necaran

Can't dump pwsh's buggy code :)

Thanks for the tip, but I've specifically replaced the default masking key /Ctrl up with this undefined key code to avoid other issues with this rather pervasive Alt menu functionality. Though don't remember exactly which ones, so maybe you're right and your approach is better on average, but I've already added terminal to the exceptions to use the old Ctrl up behavior and avoid this bug, which still needs to be fixed in this module

(smart idea re. short single taps switching layouts, I'm using the same approach)

eugenesvk avatar Mar 24 '24 05:03 eugenesvk