summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/libutil.cc
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-29 10:52:38 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2006-12-29 10:52:38 +0000
commit5bafe6551f12b7df0b5fe8ffad2f5f4ab3836718 (patch)
tree570284c09b5d48dc955102ea9b12ed77639b4c01 /crawl-ref/source/libutil.cc
parent1acc5c3b399b756f29c5f458e915052f890c266c (diff)
downloadcrawl-ref-5bafe6551f12b7df0b5fe8ffad2f5f4ab3836718.tar.gz
crawl-ref-5bafe6551f12b7df0b5fe8ffad2f5f4ab3836718.zip
[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
Diffstat (limited to 'crawl-ref/source/libutil.cc')
-rw-r--r--crawl-ref/source/libutil.cc63
1 files changed, 63 insertions, 0 deletions
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 <stdio.h>
#include <ctype.h>
#include <stdarg.h>
@@ -44,6 +45,68 @@
#include <regex.h>
#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<KeymapContext>(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)