Dwarf Fortress Bug Tracker - Dwarf Fortress
View Issue Details
0003007Dwarf FortressTechnical -- Input/Keybinding/Macrospublic2010-08-11 08:162022-04-19 14:53
0003007: Can't send shift + <whatever> to the terminal
The playing with TEXT output, pressing shift + <something> will send 'something' to the terminal, without the shift. Say, for example, trying to scroll quickly with shift + arrows doesn't work.
Set output mode to text, and try to use command that requires holding shift.
No tags attached.
parent of 0005494acknowledged lethosor Shift-enter to save changes to schedule orders does not work in TEXT print mode 
has duplicate 0006899resolved Footkerchief Modifier keys don't process correctly in text mode 
has duplicate 0008962resolved lethosor PRINT_MODE:TEXT Shift-key combinations do not work 
Not all the children of this issue are yet resolved or closed.
Issue History
2010-08-11 08:16ILikePieNew Issue
2010-08-11 08:19ILikePieNote Added: 0011717
2010-08-12 04:52ILikePieNote Edited: 0011717bug_revision_view_page.php?bugnote_id=0011717#r4578
2010-08-12 05:34BaughnNote Added: 0011742
2010-08-12 05:34BaughnStatusnew => closed
2010-08-12 05:34BaughnAssigned To => Baughn
2010-08-12 05:34BaughnResolutionopen => not fixable
2010-08-14 10:28FootkerchiefStatusclosed => resolved
2010-10-26 12:52technolemIssue Monitored: technolem
2014-07-09 19:45FootkerchiefRelationship addedhas duplicate 0006899
2014-07-09 19:45FootkerchiefStatusresolved => acknowledged
2014-07-09 19:45FootkerchiefNote Added: 0025455
2014-07-09 21:49eroppleNote Added: 0025480
2015-05-17 16:50lethosorRelationship addedhas duplicate 0008962
2015-05-17 16:53lightmanNote Added: 0032696
2015-05-17 16:53lightmanIssue Monitored: lightman
2015-05-17 17:28lethosorNote Added: 0032697
2015-05-17 17:32lethosorResolutionnot fixable => open
2015-05-17 19:09lightmanNote Added: 0032699
2015-05-17 19:28lethosorNote Added: 0032700
2015-05-17 19:42lethosorNote Edited: 0032700bug_revision_view_page.php?bugnote_id=0032700#r13088
2015-05-17 19:47lightmanNote Added: 0032701
2017-01-16 21:39TreahNote Added: 0036178
2017-04-28 13:00alexchandelNote Added: 0036474
2018-01-10 06:02huelterNote Added: 0037579
2018-01-15 06:06LociRelationship addedhas duplicate 0010526
2018-01-15 15:27lethosorRelationship replacedparent of 0010526
2020-02-18 06:09seeschlossNote Added: 0040099
2021-11-28 10:47lethosorRelationship addedparent of 0005494
2021-11-28 10:48lethosorRelationship deletedparent of 0010526
2022-04-19 14:53cizraNote Added: 0041241

2010-08-11 08:19   
(edited on: 2010-08-12 04:52)
Whoops, forgot to proof-read, please excuse any errors.

2010-08-12 05:34   
There is no portable way to deal with shift. Sorry.
2014-07-09 19:45   
Reopening due to 0006899
2014-07-09 21:49   
You can't trap keys with getch(), but libtermkey (pretty widely used these days) plays nicely with ncurses and extends it to do this. libtermkey is MIT-licensed. It's compatible with everything I know of; I've used it in Cygwin, Linux, and OS X.

http://www.leonerd.org.uk/code/libtermkey/ [^]
2015-05-17 16:53   
Why is this "not-fixable"? It's easy to distinguish between the arrow-keys and shift-arrow-keys.
2015-05-17 17:28   
These are the sequences produced in my terminal emulator (results in others may vary, but I've seen this elsewhere as well):
left: ^[[D
shift-left: ^[[1;2D
right: ^[[C
shift-right: ^[[1;2C
up: ^[[A
shift-up: ^[[A
down: ^[[B    
shift-down: ^[[B

This can probably be configured depending on the terminal emulator you're using, but as far as I know, ncurses doesn't support shift+arrow keys due to their lack of portability. I did manage to get shift+left/right to work correctly with libtermkey, so that could be a usable alternative.

("not fixable" is a field that wasn't cleared when this issue was previously reopened. Fixed.)
2015-05-17 19:09   
Thank you for updating the status. I tested the shift-arrow keys with ncurses and they are supported (using the default PuTTY terminal). In fact, the ncurses maintainer has confirmed that shift-enter will work with the right initialization of the terminal. Again, the problem I see is that DF is only allowing single-byte codes to be interpreted.
2015-05-17 19:28   
(edited on: 2015-05-17 19:42)
If DF (or ncurses, more accurately) were only interpreting single-byte codes, no arrow keys would work at all since they're represented with multiple bytes (e.g. ^[ [ A, or ESC [ A, corresponds to the up arrow). What do you mean by "they are supported"?
From my tests, neither libtermkey nor ncurses can detect Shift-Enter, and multiple sources state that this isn't possible with ncurses. If it is possible with some additional setup, can you provide a source/example?

Edit: I managed to get Shift-Up and Shift-Down to work in my terminal emulator. They appear to send different sequences by default (^[[1;2A and ^[[1;2B) in xterm, but Shift-Enter still produces the same result.

2015-05-17 19:47   
You're right about the single-byte theory and the arrow keys. I hadn't looked at that properly.

I mean that ncurses does not prohibit anything and "only knows how to read a sequence of bytes from the terminal". So, for example, I modified a simple ncurses program to make it show the code it receives for whatever key is pressed. Arrows keys and shift-arrow keys produce different codes.

When I tried in DF, it definitely registers something different for 'up' vs. 'shift-up'. I think Toady needs to look into how it interprets the input because the codes are different.

I'll look into the shift-enter scenario but I might modify PuTTY directly, to support that. I wonder what code DF expects for that combination. Maybe Toady could give me some insight.
2017-01-16 21:39   
I can confirm this is still a problem using the TEXT output on modern terminals ( gnome, Mate Term ) and the as of this writing current version of DF. 0.43.05

There has to be some type of workaround for this out there tho since the TEXT mode has been in DF for a very long time...
2017-04-28 13:00   
This can be partially fixed immediately. Shift+Left and Shift+Right are read as KEY_SLEFT and KEY_SRIGHT by ncurses, which is why they don't do anything in DF in TEXT mode right now. Many other shifted keys work like this, include Home and End.

Unfortunately, Shift+Up and Shift+Down just produce KEY_UP and KEY_DOWN, so this doesn't fully fix the problem. To deal with those (and other common/default shifted keys), you could use define_key(), which lets you define any key combination you want.
2018-01-10 06:02   
I would like to chime in. I've been playing DF exclusively on TEXT mode on an old computer as it is faster, but this Shift+Key bug is halting my progress.

The problem lies on the military menu, schedule orders. When you are assigning specific training orders to a squad, it is requested that you pres Shift+Enter to confirm the order. There is also no way to rebind this to another key.

The only solution I found is save+exit the game, restart in default mode, assign the orders that I wanted, then reload the game using TEXT. This takes about 10 minutes every time.

If the bug is not gonna be solved, I would like to ask that at least this combination be possible to rebind.

2020-02-18 06:09   
I was able to "fix" these issues (or more accurately, hack around them) from DF's key bindings screen.

First I removed the numpad bindings from the normal movement commands and assigned them to the fast movement commands, so I can now do both fine movement with the arrow keys and fast movement with the numpad. I couldn't find a way to use shift a a modifier.

And for the military screen, I simply added a new binding and pressed shift-enter there which DF interpreted as "U+A". It shows as "◙" within the interface, but works fine when I press shift-enter.

That's using DF in a screen in gnome-terminal, if it matters.
2022-04-19 14:53   
Thanks seeschloss for the hint!

I discovered that Alt+numpad works better - you can still use the numpad for regular movement, and Alt+numpad for fast movement.

Works (tested) in xorg+urxvt locally, and xorg+urxvt+SSH+tmux.

Doesn't work in Linux virtual terminal+SSH+tmux (some crtl-b or such gets detected. Perhaps you could redefine the keys and it'd start working?)