예제 #1
0
        public static bool MODS_INCLUDE_SHIFT(keycode_t key)
        {
            byte v = (byte)key;

            return((((v) >= 0x21 && (v) <= 0x2F) ||
                    ((v) >= 0x3A && (v) <= 0x60) ||
                    ((v) >= 0x7B && (v) <= 0x7E)) ? false : true);
        }
예제 #2
0
 /** Given a keycode, return its description */
 public static string keycode_find_desc(keycode_t kc)
 {
     for (int i = 0; i < mappings.Length; i++)
     {
         if (mappings[i].code == kc)
         {
             return(mappings[i].desc);
         }
     }
     return(null);
 }
예제 #3
0
        static void STORE(List <ui_event> key, int pos, byte mod, keycode_t code)
        {
            if ((mod & (byte)keycode_t.KC_MOD_CONTROL) != 0 && ENCODE_KTRL(code))
            {
                mod  = (byte)(mod & (~((byte)keycode_t.KC_MOD_CONTROL)));
                code = (keycode_t)KTRL((char)code);
            }

            //key[pos] = new ui_event();
            key[pos].key      = new keypress();
            key[pos].key.mods = mod;
            key[pos].key.code = code;
        }
예제 #4
0
 public mapping(keycode_t key, string str)
 {
     code = key;
     desc = str;
 }
예제 #5
0
 /* Analogous to isdigit() etc in ctypes */
 public static bool isarrow(keycode_t c)
 {
     return((c >= keycode_t.ARROW_DOWN) && (c <= keycode_t.ARROW_UP));
 }
예제 #6
0
 /**
  * Given a control character X, turn it into its uppercase ASCII equivalent.
  */
 public static char UN_KTRL(keycode_t X)
 {
     return((char)(X + 64));
 }
예제 #7
0
        /**
         * If keycode you're trying to apply control to is between 0x40-0x5F
         * inclusive, then you should take 0x40 from the keycode and leave
         * KC_MOD_CONTROL unset.  Otherwise, leave the keycode alone and set
         * KC_MOD_CONTROL in mods.
         *
         * This macro returns true in the former case and false in the latter.
         */
        public static bool ENCODE_KTRL(keycode_t key)
        {
            byte v = (byte)key;

            return(((v) >= 0x40 && (v) <= 0x5F) ? true : false);
        }
예제 #8
0
 /**
  * If keycode you're trying to apply control to is between 0x40-0x5F
  * inclusive, then you should take 0x40 from the keycode and leave
  * KC_MOD_CONTROL unset.  Otherwise, leave the keycode alone and set
  * KC_MOD_CONTROL in mods.
  *
  * This macro returns true in the former case and false in the latter.
  */
 public static bool ENCODE_KTRL(keycode_t key)
 {
     byte v = (byte)key;
     return (((v) >= 0x40 && (v) <= 0x5F) ? true : false);
 }
예제 #9
0
        static void STORE(List<ui_event> key, int pos, byte mod, keycode_t code)
        {
            if ((mod & (byte)keycode_t.KC_MOD_CONTROL) != 0 && ENCODE_KTRL(code)) {
                mod = (byte)(mod & (~((byte)keycode_t.KC_MOD_CONTROL)));
                code = (keycode_t)KTRL((char)code);
            }

            //key[pos] = new ui_event();
            key[pos].key = new keypress();
            key[pos].key.mods = mod;
            key[pos].key.code = code;
        }
예제 #10
0
 /**
  * Given a control character X, turn it into its uppercase ASCII equivalent.
  */
 public static char UN_KTRL(keycode_t X)
 {
     return (char)(X + 64);
 }
예제 #11
0
 public static bool MODS_INCLUDE_SHIFT(keycode_t key)
 {
     byte v = (byte)key;
     return ((((v) >= 0x21 && (v) <= 0x2F) ||
             ((v) >= 0x3A && (v) <= 0x60) ||
             ((v) >= 0x7B && (v) <= 0x7E)) ? false : true);
 }
예제 #12
0
 /**
  * The game assumes that in certain cases, the effect of a modifer key will
  * be encoded in the keycode itself (e.g. 'A' is shift-'a').  In these cases
  * (specified below), a keypress' 'mods' value should not encode them also.
  *
  * If the character has come from the keypad:
  *   Include all mods
  * Else if the character is in the range 0x01-0x1F, and the keypress was
  * from a key that without modifiers would be in the range 0x40-0x5F:
  *   CONTROL is encoded in the keycode, and should not be in mods
  * Else if the character is in the range 0x21-0x2F, 0x3A-0x60 or 0x7B-0x7E:
  *   SHIFT is often used to produce these should not be encoded in mods
  *
  * (All ranges are inclusive.)
  *
  * You can use these macros for part of the above conditions.
  */
 public static bool MODS_INCLUDE_CONTROL(keycode_t key)
 {
     byte v = (byte)key;
     return (((v) >= 0x01 && (v) <= 0x1F) ? false : true);
 }
예제 #13
0
 /** Given a keycode, return its description */
 public static string keycode_find_desc(keycode_t kc)
 {
     for (int i = 0; i < mappings.Length; i++) {
         if (mappings[i].code == kc){
             return mappings[i].desc;
         }
     }
     return null;
 }
예제 #14
0
 /* Analogous to isdigit() etc in ctypes */
 public static bool isarrow(keycode_t c)
 {
     return ((c >= keycode_t.ARROW_DOWN) && (c <= keycode_t.ARROW_UP));
 }
예제 #15
0
 public mapping(keycode_t key, string str)
 {
     code = key;
     desc = str;
 }
예제 #16
0
        /** Convert a string of keypresses into their textual representation */
        public static string keypress_to_text(ui_event[] src, bool expand_backslash)
        {
            string buf = "";

            foreach (ui_event evt in src)
            {
                if (evt.type != ui_event_type.EVT_KBRD)
                {
                    break;
                }

                keycode_t i    = evt.key.code;
                byte      mods = evt.key.mods;
                string    desc = keycode_find_desc(i);

                /* un-ktrl control characters if they don't have a description */

                /* this is so that Tab (^I) doesn't get turned into ^I but gets
                 * displayed as [Tab] */
                if ((byte)i < 0x20 && desc == null)
                {
                    mods |= (byte)keycode_t.KC_MOD_CONTROL;
                    i     = (keycode_t)UN_KTRL(i);
                }

                if (mods != 0)
                {
                    if (((mods & (byte)keycode_t.KC_MOD_CONTROL) != 0) && (mods & ~(byte)keycode_t.KC_MOD_CONTROL) == 0)
                    {
                        buf += "^";
                    }
                    else
                    {
                        buf += "{";
                        if ((mods & (byte)keycode_t.KC_MOD_CONTROL) != 0)
                        {
                            buf += "^";
                        }
                        if ((mods & (byte)keycode_t.KC_MOD_SHIFT) != 0)
                        {
                            buf += "S";
                        }
                        if ((mods & (byte)keycode_t.KC_MOD_ALT) != 0)
                        {
                            buf += "A";
                        }
                        if ((mods & (byte)keycode_t.KC_MOD_META) != 0)
                        {
                            buf += "M";
                        }
                        if ((mods & (byte)keycode_t.KC_MOD_KEYPAD) != 0)
                        {
                            buf += "K";
                        }
                        buf += "}";
                    }
                }

                if (desc != null)
                {
                    buf += "[" + desc + "]";
                }
                else
                {
                    switch ((char)i)
                    {
                    case '\a': buf += "\a"; break;

                    case '\\': {
                        if (expand_backslash)
                        {
                            buf += "\\\\";
                        }
                        else
                        {
                            buf += "\\";
                        }
                        break;
                    }

                    case '^': buf += "\\^"; break;

                    case '[': buf += "\\["; break;

                    default: {
                        if ((char)i < 127)
                        {
                            buf += (char)i;
                        }
                        else
                        {
                            buf += "\\x" + i.ToString("X2");
                        }
                        break;
                    }
                    }
                }
            }

            return(buf);
        }
예제 #17
0
        /**
         * The game assumes that in certain cases, the effect of a modifer key will
         * be encoded in the keycode itself (e.g. 'A' is shift-'a').  In these cases
         * (specified below), a keypress' 'mods' value should not encode them also.
         *
         * If the character has come from the keypad:
         *   Include all mods
         * Else if the character is in the range 0x01-0x1F, and the keypress was
         * from a key that without modifiers would be in the range 0x40-0x5F:
         *   CONTROL is encoded in the keycode, and should not be in mods
         * Else if the character is in the range 0x21-0x2F, 0x3A-0x60 or 0x7B-0x7E:
         *   SHIFT is often used to produce these should not be encoded in mods
         *
         * (All ranges are inclusive.)
         *
         * You can use these macros for part of the above conditions.
         */
        public static bool MODS_INCLUDE_CONTROL(keycode_t key)
        {
            byte v = (byte)key;

            return(((v) >= 0x01 && (v) <= 0x1F) ? false : true);
        }
예제 #18
0
        /*
         * Some special machines need their own "main()" function, which they
         * can provide here, making sure NOT to compile the "main.c" file.
         *
         * These systems usually have some form of "event loop", run forever
         * as the last step of "main()", which handles things like menus and
         * window movement, and calls "play_game(false)" to load a game after
         * initializing "savefile" to a filename, or "play_game(true)" to make
         * a new game.  The event loop would also be triggered by "Term_xtra()"
         * (the TERM_XTRA_EVENT action), in which case the event loop would not
         * actually "loop", but would run once and return.
         */


        /*
         * An event handler XXX XXX XXX
         *
         * You may need an event handler, which can be used by both
         * by the "TERM_XTRA_BORED" and "TERM_XTRA_EVENT" entries in
         * the "Term_xtra_xxx()" function, and also to wait for the
         * user to perform whatever user-interface operation is needed
         * to request the start of a new game or the loading of an old
         * game, both of which should launch the "play_game()" function.
         */
        static bool CheckEvents(bool wait)
        {
            if (wait || Console.KeyAvailable)
            {
                int i = 0;
                while (!Console.KeyAvailable)
                {
                    Thread.Sleep(20);

                    if (i == 0)
                    {
                        Dungeon.idle_update();
                    }
                    i = (i + 1) % 10;
                }

                ConsoleKeyInfo ck      = Console.ReadKey(true);
                keycode_t      to_send = (keycode_t)ck.KeyChar;
                keycode_t      mods    = keycode_t.KC_NONE;

                if (ck.Key == ConsoleKey.DownArrow)
                {
                    to_send = keycode_t.ARROW_DOWN;
                }
                else if (ck.Key == ConsoleKey.UpArrow)
                {
                    to_send = keycode_t.ARROW_UP;
                }
                else if (ck.Key == ConsoleKey.LeftArrow)
                {
                    to_send = keycode_t.ARROW_LEFT;
                }
                else if (ck.Key == ConsoleKey.RightArrow)
                {
                    to_send = keycode_t.ARROW_RIGHT;
                }
                else if (ck.Key == ConsoleKey.Enter)
                {
                    to_send = keycode_t.KC_ENTER;
                }
                else if (ck.Key == ConsoleKey.Escape)
                {
                    to_send = keycode_t.ESCAPE;
                }
                else if (ck.Key == ConsoleKey.Backspace)
                {
                    to_send = keycode_t.KC_BACKSPACE;
                }

                if (ck.Modifiers == ConsoleModifiers.Shift)
                {
                    mods = keycode_t.KC_MOD_SHIFT;
                }
                else if (ck.Modifiers == ConsoleModifiers.Control)
                {
                    mods = keycode_t.KC_MOD_CONTROL;
                }
                else if (ck.Modifiers == ConsoleModifiers.Alt)
                {
                    mods = keycode_t.KC_MOD_ALT;
                }
                Term.keypress(to_send, (byte)mods);
            }

            return(true);
        }
예제 #19
0
 public keypress()
 {
     code = keycode_t.KC_NONE;
     mods = 0;
 }