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."
source share