termbox-go icon indicating copy to clipboard operation
termbox-go copied to clipboard

How to handle ctrl + Arrow keys input using termbox-go?

Open acmeofevolution opened this issue 11 years ago • 5 comments

Can you please explain how one can handle "Ctrl + ArrowX" keys where X=Up, Down, Left, Right? Currently, my app using termbox-go just quits as soon as I hit Ctrl + any Arrow key, and so are most of the _demos/.go sample programs, except keyboard.go. Any documentation or explanation around it will be quite useful. Ideally, I would like to either handle it and take some action or at least make sure, my app doesn't just quit when user hits this key combination.

acmeofevolution avatar Dec 30 '14 19:12 acmeofevolution

Termbox doesn't support them. Any unknown esc key sequence (ctrl+arrow keys are esc seqs) is recognized as esc and characters which follow. The reason for this is that termbox supports only a common subset of functionality all most popular terminals support.

There is no way to avoid that behaviour, unless you simply ignore esc. I've said that many times and I'm happy to repeat: terminals suck when it comes to input, you have to live with it or use something else than a terminal. That's why editors like vim and emacs have a very restricted set of bindings by default. Both vim and emacs don't even use arrow keys mainly and recommend to use other keys (C-f C-b C-n C-p or hjkl). Yes, they do support it eventually, but as I said, not all terminals handle ctrl+arrow keys properly.

I'm strongly against building interfaces which aren't portable (i.e. don't work on all platforms). Yes, termbox became already that kind of a library, where on linux there are 256 colors and on windows there is no such thing. Initially termbox was born because I tried doing portable stuff (linux and windows) using some w32 curses port and it simply didn't work well.

So, whatever, I don't know what to do about it.

nsf avatar Dec 30 '14 19:12 nsf

I'm adding raw events to the termbox. See: https://github.com/nsf/termbox-go/pull/65

And the commit: https://github.com/nsf/termbox-go/commit/54b74d087b7c397c402d0e3b66d2ccb6eaf5c2b4

Technically, it's a way to handle Ctrl+Arrow keys. Maybe not the best one, but it is.

nsf avatar Feb 15 '15 09:02 nsf

Control+Arrow can't work on most terminals -- there is no escape sequence defined for it, and so its generally impossible outside of Windows.

gdamore avatar Sep 21 '15 22:09 gdamore

Control+arrow works on all terminal emulators I've tried (on Linux) and it's supported in programs like vim. Can these keys be added to termbox-go so it's easy to work with?

Limero avatar Jul 22 '19 11:07 Limero

Termbox is no longer maintained, you can try this lib: https://github.com/gdamore/tcell

It might support what you're looking for.

nsf avatar Jul 22 '19 11:07 nsf