Skip to content

Pls add support shift+tab #80

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

Closed
fleytman opened this issue Jul 7, 2022 · 5 comments
Closed

Pls add support shift+tab #80

fleytman opened this issue Jul 7, 2022 · 5 comments

Comments

@fleytman
Copy link
Contributor

fleytman commented Jul 7, 2022

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'
@Cube707
Copy link
Collaborator

Cube707 commented Jul 9, 2022

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...

@fleytman
Copy link
Contributor Author

fleytman commented Jul 11, 2022

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.

@Cube707
Copy link
Collaborator

Cube707 commented Jul 11, 2022

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.

@fleytman
Copy link
Contributor Author

fleytman commented Jul 14, 2022

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.

fleytman added a commit to fleytman/python-readchar that referenced this issue Jul 14, 2022
fleytman added a commit to fleytman/python-readchar that referenced this issue Jul 14, 2022
@fleytman fleytman mentioned this issue Jul 14, 2022
@fleytman
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants