Skip to content

Pls add support shift+tab #80

Closed
Closed

Description

@fleytman

I want use shift tab in inquirer. But readchar not read this keyevent

    print("Press a key")
    key = readchar.readkey()
    print("Key is {0}".format(key.encode()))
>>>Press a key
>>>shift+tab
>>>Key is b'\t'

Activity

  1. Cube707 commented on Jul 9, 2022

    @Cube707
    Collaborator

    You didn't provide this crutial information, but from the fact that you only get a single TAB back, I assume you are on windows?

    Windows doesn't modify the tab-key when pressing shift, it always just reads TAB. So it is imposible to use TAB+SHIFT on windows, this has nothing to do with readchar() but is simply a windows limitation.

    We could add it to the Linux side, but I would still not recomend using it as it is not portable...

  2. fleytman commented on Jul 11, 2022

    @fleytman
    ContributorAuthor

    I'm use macos. It’s a pity that it won’t work for Windows, of course I want a cross-platform implementation. But support for *nix would also be nice.
    If you think about support in windows, is it possible to have a solution for a power shell or a windows terminal? As a last resort, there is wsl or cygwin.

  3. Cube707 commented on Jul 11, 2022

    @Cube707
    Collaborator

    For *nix support

    This will have to wait but will probably come at some point. For now the project maintainer is not responding and untill he does I am just a powerless contributer myself. You can however, for the ime beeing, patch the key-module for unix systems with this line after your readchar import:

    from readchar import readkey, key
    key.SHIFT_TAB = "\x1b\x5b\x5a"

    Now you can use it as expected:

    while True:
        k = readkey()
        if k == key.SHIFT_TAB:
            print("got macro shortcut!!!!!")

    You can get the codes for other unsported keys by running my testing script, it will print you the codes for all pressed keys.

    For windows support:

    readchar relies on the standart libary msvcrt to do the actuall terminal interaction. If you take this exapmple:

    from msvcrt import getch
    
    while True:
    	k = getch()
    	print(k)

    you will see that both pressing TAB and SHIFT+TAB result in the same output of b'\t'. Windows doesn't provide this keycombination to python so it is imposible to handle it.

  4. fleytman commented on Jul 14, 2022

    @fleytman
    ContributorAuthor

    Thanks for your answer. I found why I can't use readchar.readkey(), it's #11 problem. Pycharm terminal != system terminal. In system macos term i can read shift+tab.

  5. added 2 commits that reference this issue on Jul 14, 2022
  6. fleytman commented on Jul 14, 2022

    @fleytman
    ContributorAuthor

    It's work with inquirer magmax/python-inquirer#170

  7. added a commit that references this issue on Jul 25, 2022
    bc8e2f1
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions