Path: csiph.com!news.swapon.de!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: Parsing multi-byte keystrokes Date: Mon, 26 Jun 2023 16:26:38 -0700 Organization: None to speak of Lines: 43 Message-ID: <87zg4lyfdd.fsf@nosuchdomain.example.com> References: <87edlz5cax.fsf@bsb.me.uk> <877crq4cbp.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="a853ce57f0cc376f52e20a2b97585134"; logging-data="1183766"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dZ98wCJAivE5eTogMr9jq" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:PV7ZtA9TpniqhHy+PfdVd0d/4o4= sha1:hPTwv7QyExs8HtaMCll+C/FiEhk= Xref: csiph.com comp.lang.c++:90770 Christian Gollwitzer writes: > Am 26.06.23 um 22:48 schrieb R.Wieser: >> Christian, >> >>> As written above, you can use the termcap or terminfo library. It tells >>> you what keystrokes correspond to which keys. >> A quick search shows me that "termcap" is a textfile which as been >> marked >> obsolete and that both are used to translate keystrokes into escape >> sequences. There where no results shown in regard to translating escape >> sequences back to keystrokes though. >> IOW, do you have any link(s) that show how the latter is supposed to >> be done >> ? > > The termcap library is only a way to do the forward translation, > i.e. you can ask it for a key and get back the string that is > represented like this: > https://stackoverflow.com/questions/55090078/termcap-tgetstr-getting-arrow-keys No, terminfo is newer and is intended to replace termcap, and provides the same information. If you're starting something new, ignore termcap and use terminfo (unless you have some specific requirement to use termcap). > However, I still believe you are much better off using the ncurses > library, which also does the backwards translation. Look, e.g. at this > example: > > https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/keys.html > > As you can see here, the getch() function translates the special keys > to their symbolic code liek KEY_UP etc. Yes, but it's not suitable for the OP's purposes. getch() implicitly refers to the current ncurses screen (stdscr), and it can't be used without first setting things up properly, which takes over the terminal screen. (And comp.lang.c++ isn't the place to ask about it.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */