You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@suresttexas00 Have you tried if the arrows work with the code in PR #13 ? I remember I fixed that for at least Windows, but I might have fixed it for linux as well... I can't remember.
# -*- coding: utf-8 -*-
import readchar
while True:
keypress = readchar.readkey()
print(keypress)
if keypress in (readchar.key.CR, readchar.key.CTRL_C):
break
UP, RIGHT, DOWN, LEFT produces:
^[[B^[[D
It is entirely random (Somewhere between the 1st and 3rd keypress) when a ^[[* character is printed. I am sure there might be a pattern that a gifted autistic might note; but I suck and it seems random to me :)
The way special characters can be printed under Linux at the moment is different than on Windows. Try the following before anything else. Maybe it actually works:
If not, you probably need to look at the raw values returned by the following function in order to fix the arrows on linux char = os.read(sys.stdin.fileno(), 1)
You might need more than one call to this function to get all the data from a single key press. Maybe there is a missing escape sequence in key.py that prevents getting the arrows.
I rewrote readchar_linux.py using the same logic and it now appears to detect the arrow keys now:
import sys
import os
import select
import tty
import termios
from . import key
def readchar(wait_for_char=True):
old_settings = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin.fileno())
charbuffer = ''
while True:
char1 = getkey(wait_for_char, old_settings)
if (charbuffer + char1) not in key.ESCAPE_SEQUENCES:
return charbuffer + char1
charbuffer += char1
def getkey(wait_for_char, old_settings):
charbuffer = ''
try:
if wait_for_char or select.select([sys.stdin, ], [], [], 0.0)[0]:
char = os.read(sys.stdin.fileno(), 1)
charbuffer = char if type(char) is str else char.decode()
except Exception:
pass
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
return charbuffer
I'm sure that could be a little cleaner.. like I am not sure the wait_for_char argument is needed (or even the whole try:except) since readchar is not calling instances of itself here.
The next step would be to take these linux constants and map them to the same readable string values you are using in the windows version, so that they will compare equally on either system.
Release 1.0 tried to manage ESC key, but it is very confusing and obfuscate the code a lot. So I backtrack to 0.7 with some minor changes, where arrow keys were working fine.
Activity
[-]Usage info for readchar() of arrow keys[/-][+]arrow keys not being sent to readkey()[/+]guiweber commentedon Mar 10, 2017
@suresttexas00 Have you tried if the arrows work with the code in PR #13 ? I remember I fixed that for at least Windows, but I might have fixed it for linux as well... I can't remember.
suresttexas00 commentedon Mar 10, 2017
I'm working on testing that now. So far, all I know is that nothing is broken :P
suresttexas00 commentedon Mar 10, 2017
UP, RIGHT, DOWN, LEFT produces:
It is entirely random (Somewhere between the 1st and 3rd keypress) when a ^[[* character is printed. I am sure there might be a pattern that a gifted autistic might note; but I suck and it seems random to me :)
guiweber commentedon Mar 10, 2017
The way special characters can be printed under Linux at the moment is different than on Windows. Try the following before anything else. Maybe it actually works:
If not, you probably need to look at the raw values returned by the following function in order to fix the arrows on linux
char = os.read(sys.stdin.fileno(), 1)You might need more than one call to this function to get all the data from a single key press. Maybe there is a missing escape sequence in key.py that prevents getting the arrows.
suresttexas00 commentedon Mar 10, 2017
I rewrote readchar_linux.py using the same logic and it now appears to detect the arrow keys now:
I'm sure that could be a little cleaner.. like I am not sure the
wait_for_charargument is needed (or even the whole try:except) since readchar is not calling instances of itself here.suresttexas00 commentedon Mar 10, 2017
The next step would be to take these linux constants and map them to the same readable string values you are using in the windows version, so that they will compare equally on either system.
have in keys.py:
and then have the charbuffer scrubbed to replace:
suresttexas00 commentedon Mar 14, 2017
Release 0.8
magmax commentedon Mar 14, 2017
Release 1.0 tried to manage ESC key, but it is very confusing and obfuscate the code a lot. So I backtrack to 0.7 with some minor changes, where arrow keys were working fine.
Thank you anyways for your effort.
suresttexas00 commentedon Mar 15, 2017
got a new pull request based on my comment about # 1 fix above (so # 2 is still an issue - cant' get Esc key by itself or F11/F12.
suresttexas00 commentedon Mar 15, 2017
I could probably fix that too, but it might break the windows part... and I own no windoze machines to test! :)