Game Development Community

BUG: XKeyboardDevice.PumpDevice

by Scott Goodwin · in Torque X 2D · 03/20/2008 (8:50 am) · 0 replies

There's a typo in the code (the second occurence of Keys.RightAlt should be Keys.LeftShift). Here's the bugfix (note, while I'm at it, I've also added support for the Alt modifier).

In XKeyboardDevice.PumpDevice
#region BUG(SDG)
#if !SDG_APPLY_BUGFIXES
                    if (key != Keys.LeftAlt && key != Keys.RightAlt &&
                        key != Keys.RightAlt && key != Keys.RightShift &&
                        key != Keys.LeftControl && key != Keys.RightControl)
                    {
                        if (currentState.IsKeyDown(Keys.LeftControl) || currentState.IsKeyDown(Keys.RightControl))
                            data.Modifier |= Action.Ctrl;
                        if (currentState.IsKeyDown(Keys.LeftShift) || currentState.IsKeyDown(Keys.RightShift))
                            data.Modifier |= Action.Shift;
#endif
        #endregion
         
        #region BUGFIX(SDG)
#if SDG_APPLY_BUGFIXES
                    if (key != Keys.LeftAlt && key != Keys.RightAlt &&
                        key != Keys.LeftShift && key != Keys.RightShift &&
                        key != Keys.LeftControl && key != Keys.RightControl)
                    {
                        if (currentState.IsKeyDown(Keys.LeftControl) || currentState.IsKeyDown(Keys.RightControl))
                            data.Modifier |= Action.Ctrl;
                        if (currentState.IsKeyDown(Keys.LeftShift) || currentState.IsKeyDown(Keys.RightShift))
                            data.Modifier |= Action.Shift;
                        #region CODE ADDED(SDG)
                        // add support for Alt modifier (must change Action enum as well)
#if SDG_APPLY_CODE_CHANGES
                        if (currentState.IsKeyDown(Keys.LeftAlt) || currentState.IsKeyDown(Keys.RightAlt))
                            data.Modifier |= Action.Alt;
#endif
                        #endregion
#endif
        #endregion

and to add the Alt modifier, in TorqueInputDevice.Action:
/// <summary>
            /// A modifier which signifies that an event occured with the shift key held down.
            /// </summary>
            Shift, 
            /// <summary>
            /// A modifier which signifies that an event occured with the control key held down.
            /// </summary>
            Ctrl,
            #region CODE ADDED(SDG)
            // add support for Alt modifier
#if SDG_APPLY_CODE_CHANGES
            /// <summary>
            /// A modifier which signifies that an event occured with the alt key held down.
            /// </summary>
            Alt, 
#endif
            #endregion