Skip to content

Up and down arrow keys do not work on Linux or Mac due to Dotnet.core bug. #11

Closed

Description

@mark-hubers

I looked into this and made a fixed on my local system and I was going to make a PR for it but this project is locked down I believed. So here what I did to make this great menu work on Linux and Mac so one can use the up and down arrow vs crashing out of the menu.

In file: PSMenu/Private/Read-VKey.ps1 I added the following:

    try {
        return $CurrentHost.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    }

to

     try {
        if ($IsLinux -or $IsMacOS) {
            ## A bug with Linux and Mac where arrow keys are return in 2 chars.  First is esc follow by A,B,C,D
            $key1 = $CurrentHost.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
            
            if ($key1.VirtualKeyCode -eq 0x1B) {
            ## Found that we got an esc chair so we need to grab one more char
            $key2 = $CurrentHost.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

                ## We just care about up and down arrow mapping here for now.
                if ($key2.VirtualKeyCode -eq 0x41) {
                    # VK_UP = 0x26 up-arrow
                    $key1.VirtualKeyCode = 0x26
                }
                if ($key2.VirtualKeyCode -eq 0x42) {
                    # VK_DOWN = 0x28 down-arrow
                    $key1.VirtualKeyCode = 0x28
                }
            }
            Return $key1
        } else {
            return $CurrentHost.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
        }
    }

Hope this helps.

Activity

  1. changed the title [-]Up and down arrow keys do not work on Linux or Mac due to C# bug.[/-] [+]Up and down arrow keys do not work on Linux or Mac due to Dotnet.core bug.[/+] on May 23, 2022
  2. Sebazzz commented on May 23, 2022

    @Sebazzz
    Owner

    Thank you. I don't think the project is locked down, but I did just make a few commits so you might run into a merge conflict.

    You mention there is a .NET bug - is it tracked upstream, and if so, under which number?

  3. mark-hubers commented on May 23, 2022

    @mark-hubers
    Author

    It is a hard problem to point out but here are some refs:
    PowerShell/PowerShell#16443
    dotnet/runtime#63387
    PowerShell/PowerShell#16606

  4. Sebazzz commented on May 25, 2022

    @Sebazzz
    Owner

    Thanks, released as v0.1.8!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions