How to get Shift + X / Alt + X keys in Curses?

I am currently using this code to capture keys, but I am missing, for example. Shift / Alt , such as Ctrl + Shift + S , Ctrl + Shift + ↑ , Alt + S , etc.

require 'curses' Curses.noecho Curses.raw Curses.stdscr.keypad(true) Curse.nonl count = 0 loop do count = (count + 1) % 20 key = Curses.getch break if key == ?\Cc Curses.setpos(count,0) Curses.addstr("#{key.inspect} "); end 

Is there any way to capture them all?

Also: how can I distinguish between Ctrl + J / Ctrl + M from Ctrl + Enter / Enter , which give the same key codes ( 13 )?

+1
source share
1 answer

also: how to distinguish ctrl + j / ctrl + m from ctr + enter / enter, which give the same key codes (10/13)

In short, you cannot. A terminal will almost certainly give the same bytes for each. Read please

http://www.leonerd.org.uk/hacks/fixterms/

However, if you feel particularly brave, you can try my libtermkey

http://www.leonerd.org.uk/code/libtermkey/

which will at least correctly analyze things like Ctrl-arrow . It does not yet have a Ruby binding, but having both Perl and Python suggests that it should be fairly easy to write.

Finally, if you feel even more courageous, you can run the terminal I wrote, pangoterm , which has common ways to encode any randomly modified Unicode keys, so it can distinguish Ctrl-m from Enter, etc.

https://launchpad.net/pangoterm

However, outside of them, the answer remains "you cannot."

+4
source

Source: https://habr.com/ru/post/910986/


All Articles