Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Fix Text-Mode Keyboard Input  (Read 1376 times)

Lightman

  • Bay Watcher
  • The groboclones are looking for you.
    • View Profile
Fix Text-Mode Keyboard Input
« on: January 25, 2015, 10:02:47 pm »

I've noticed that shift-keys don't work in text mode, such as shift + arrow keys.  This seems to be related to how DF interprets the keyboard codes (it doesn't read the sequence properly for shift-key codes).  I'd like to see this working, especially for SSH sessions.

Thanks!
Logged

lethosor

  • Bay Watcher
    • View Profile
Re: Fix Text-Mode Keyboard Input
« Reply #1 on: January 25, 2015, 11:04:08 pm »

These are the escape sequences produced by arrow keys on my terminal (on OS X - I'm fairly certain that these are the same on my Linux machine):
Code: [Select]
up: ^[[A
shift-up: ^[[A
down: ^[[B
shift-down: ^[[B
left:    ^[[D
shift-left: ^[[1;2D
right: ^[[C
shift-right: ^[[1;2C
In short, there's no way for ncurses to differentiate between shift+up and up (and shift+down and down). According to feedback on this bug report, libtermkey might be a usable alternative (although I have no idea how it works, or if it would work over SSH). It's also not possible to test changes like this on OS X, since libgraphics is statically linked, so trying to implement this for OS X and Linux while testing only on Linux could be difficult (and trying to maintain separate input systems on each platform would be worse).
Regardless of that, I do support this. In the meantime, I've found that binding to Alt+arrow keys works well enough (or you can use shift+numpad keys if your keyboard has a numpad).
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.

Lightman

  • Bay Watcher
  • The groboclones are looking for you.
    • View Profile
Re: Fix Text-Mode Keyboard Input
« Reply #2 on: January 26, 2015, 01:23:18 am »

These are the escape sequences produced by arrow keys on my terminal (on OS X - I'm fairly certain that these are the same on my Linux machine):
Code: [Select]
[...]In short, there's no way for ncurses to differentiate between shift+up and up (and shift+down and down). According to feedback on this bug report, libtermkey might be a usable alternative (although I have no idea how it works, or if it would work over SSH). It's also not possible to test changes like this on OS X, since libgraphics is statically linked, so trying to implement this for OS X and Linux while testing only on Linux could be difficult (and trying to maintain separate input systems on each platform would be worse).
Regardless of that, I do support this. In the meantime, I've found that binding to Alt+arrow keys works well enough (or you can use shift+numpad keys if your keyboard has a numpad).

When I SSH, shift+arrow-keys (including up/down) send different codes, which can be demonstrated with a simple ncurses program.  I just tested that to be sure, using Debian Linux.

Thanks, I'll check out the bug report.  I may use the alt+arrow-keys binding you mention, though it would be nice to get shift+arrow-keys working.  I also need to see if I can make shift-enter work, somehow.  Perhaps I can re-map that functionality.

I did create a custom version of PuTTY that lets me use the numerical keypad, as normal.  One more step in the right direction... :)
Logged