From 5bafe6551f12b7df0b5fe8ffad2f5f4ab3836718 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Fri, 29 Dec 2006 10:52:38 +0000 Subject: [1622126] Fixed shift+direction keys canceling the targeting prompt. Hopefully this works on Windows and DOS, but I'm unsure. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@723 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/libutil.cc | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'crawl-ref/source/libutil.cc') diff --git a/crawl-ref/source/libutil.cc b/crawl-ref/source/libutil.cc index 181dd180bf..061113adc7 100644 --- a/crawl-ref/source/libutil.cc +++ b/crawl-ref/source/libutil.cc @@ -16,6 +16,7 @@ #include "initfile.h" #include "libutil.h" #include "externs.h" +#include "macro.h" #include #include #include @@ -44,6 +45,68 @@ #include #endif +#ifdef UNIX +static keycode_type numpad2vi(keycode_type key) +{ + if (key >= '1' && key <= '9') + { + const char *vikeys = "bjnh.lyku"; + return keycode_type(vikeys[key - '1']); + } + return (key); +} +#endif + +int unmangle_direction_keys(int keyin, int km) +{ + const KeymapContext keymap = static_cast(km); +#ifdef UNIX + // Kludging running and opening as two character sequences + // for Unix systems. This is an easy way out... all the + // player has to do is find a termcap and numlock setting + // that will get curses the numbers from the keypad. This + // will hopefully be easy. + + /* can we say yuck? -- haranp */ + if (keyin == '*') + { + keyin = getchm(keymap); + // return control-key + keyin = CONTROL(toupper(numpad2vi(keyin))); + } + else if (keyin == '/') + { + keyin = getchm(keymap); + // return shift-key + keyin = toupper(numpad2vi(keyin)); + } +#else + // Old DOS keypad support + if (keyin == 0) + { + /* FIXME haranp - hackiness */ + const char DOSidiocy[10] = { "OPQKSMGHI" }; + const char DOSunidiocy[10] = { "bjnh.lyku" }; + const int DOScontrolidiocy[9] = { + 117, 145, 118, 115, 76, 116, 119, 141, 132 + }; + keyin = getchm(keymap); + for (int j = 0; j < 9; ++j ) { + if (keyin == DOSidiocy[j]) { + keyin = DOSunidiocy[j]; + break; + } + if (keyin == DOScontrolidiocy[j]) { + keyin = CONTROL(toupper(DOSunidiocy[j])); + break; + } + } + } +#endif + + return (keyin); +} + // Should return true if the filename contains nothing that // the shell can do damage with. bool shell_safe(const char *file) -- cgit v1.2.3-54-g00ecf