Esempio n. 1
0
        public void ReadInput(ref int keyboard_read_data, int keyboard_row)
        {
            if (MenuInputComponent.MenuStillDebouncing())
            {
                // Ignore keypresses if we just came from the menu system
                return;
            }

            // Matches the row this joystick is mapped to?
            if (keyboard_row == JOYSTICK_KEY_ROWS[m_joystick_index])
            {
                // Grab XNA pad state
                // TODO: Read once per frame
                GamePadState pad_state = GamePad.GetState(m_xna_gamepad_index);

                for (int i = 0; i < NUM_JOYSTICK_KEYS; i++)
                {
                    // Check each button combo
                    for (int j = 0; j < XNA_BUTTONS_PER_KEY; j++)
                    {
                        // If pressed, unset this bit
                        if (pad_state.IsButtonDown(JOYSTICK_KEY_BIT_MAPPING[i, j]))
                        {
                            keyboard_read_data &= (~(1 << i));     // Indice here is also the bit to unset in the keyboard matrix
                            break;
                        }
                    }
                }
            }

#if XBOX
            // HACK: Hack to map enter and space onto Xbox controlpads
            const int ENTER_KEY_ROW = 0x02;
            const int ENTER_KEY_BIT = 0x02;
            const int SPACE_KEY_ROW = 0x05;
            const int SPACE_KEY_BIT = 0x07;

            if (keyboard_row == ENTER_KEY_ROW)
            {
                if (GamePad.GetState(m_xna_gamepad_index).IsButtonDown(Buttons.Y))
                {
                    keyboard_read_data &= (~(1 << ENTER_KEY_BIT));
                }
            }
            if (keyboard_row == SPACE_KEY_ROW)
            {
                if (GamePad.GetState(m_xna_gamepad_index).IsButtonDown(Buttons.X))
                {
                    keyboard_read_data &= (~(1 << SPACE_KEY_BIT));
                }
            }
#endif // XBOX
        }
Esempio n. 2
0
        public int ReadCurrentRow()
        {
            if (MenuInputComponent.MenuStillDebouncing())
            {
                // Ignore keypresses if we just came from the menu system
                return(0xFF);
            }

            if (m_current_row > KEYBOARD_MAP.GetUpperBound(0))
            {
                return(0xFF);
            }

            // TODO: Read once per frame
            KeyboardState key_states = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            int return_value = 0xFF;

            for (int i = 0; i < KEYS_PER_ROW; i++)
            {
                Keys key = KEYBOARD_MAP[m_current_row, i];

                if (key_states.IsKeyDown(key))
                {
                    return_value &= ~(1 << i);
                }

                // Horrible special case so that both shift keys work... The keyboard map logic is nice, so I'd hate to add
                // a third dimension to support multiple XNA-keys per CPC-key.
                if (key == Keys.LeftShift)
                {
                    if (key_states.IsKeyDown(Keys.RightShift))
                    {
                        return_value &= ~(1 << i);
                    }
                }
            }

            foreach (Joystick joystick in m_joysticks)
            {
                joystick.ReadInput(ref return_value, m_current_row);
            }

            return(return_value);
        }