Exemplo n.º 1
0
        /// <summary>
        /// Checks the button state based on the raw data returned, and if it has, the ButtonStateChanged event is raised
        /// </summary>
        /// <param name="buf">Raw data buffer retrieved from the controller</param>
        private void CheckStateChanged(byte[] buf)
        {
            ButtonEnum[] values = (ButtonEnum[])Enum.GetValues(typeof(ButtonEnum));
            stateChangedArray = new ButtonState[values.Length];
            bool updateLights = false;

            for (int i = 0; i < values.Length; i++)
            {
                ButtonMasks.ButtonMask mask = ButtonMasks.MaskList[(int)values[i]];

                ButtonState state = new ButtonState();
                state.button       = (ButtonEnum)values[i];
                state.currentState = ((buf[mask.bytePos] & mask.maskValue) > 0);
                state.changed      = isStateChanged(buf, mask.bytePos, mask.maskValue);
                ButtonEnum currentButton = (ButtonEnum)(i);

                //only do something if button changed, and button was pressed and button is in hashtable
                if (state.changed)
                {
                    if (updateGearLights && state.button == ButtonEnum.GearLeverStateChange)
                    {
                        GearLightsRefresh((int)unchecked ((sbyte)buf[25]));//copied this code from GearLever accessor, changed it since we need ot
                        updateLights = true;
                    }
                    //check button - light mapping
                    if (ButtonLights.ContainsKey(i))
                    {
                        updateLights = true;
                        LightProperties currentLightProperties = (LightProperties)(ButtonLights[i]);

                        if (currentLightProperties.lightOnHold)
                        {
                            if (state.currentState)
                            {
                                SetLEDState(currentLightProperties.LED, currentLightProperties.intensity, false);
                            }
                            else
                            {
                                SetLEDState(currentLightProperties.LED, 0, false);
                            }
                        }
                        else
                        if (state.currentState)                                //only switch when button is pressed
                        {
                            int result = GetLEDState(currentLightProperties.LED);
                            if (result > 0)                                    //light is on
                            {
                                SetLEDState(currentLightProperties.LED, 0);    //turn off
                            }
                            else
                            {
                                SetLEDState(currentLightProperties.LED, currentLightProperties.intensity);
                            }
                        }
                    }
                    if (ButtonKeys.ContainsKey(i))
                    {
                        KeyProperties currentKeyProperties = (KeyProperties)(ButtonKeys[i]);
                        if (currentKeyProperties.useModifier)
                        {
                            if (state.currentState)//button is pressed, then press key
                            {
                                InputSimulator.SimulateModifiedKeyStroke(currentKeyProperties.modifier, currentKeyProperties.keyCode1);
                            }
                        }
                        else
                        {
                            if (currentKeyProperties.holdDown)                            //send separate down and up keypresses
                            {
                                if (state.currentState)
                                {
                                    InputSimulator.SimulateKeyDown(currentKeyProperties.keyCode1);
                                }
                                else
                                {
                                    InputSimulator.SimulateKeyUp(currentKeyProperties.keyCode1);
                                }
                            }
                            else
                            {
                                if (state.currentState)
                                {
                                    InputSimulator.SimulateKeyPress(currentKeyProperties.keyCode1);
                                }
                            }
                        }
                    }
                }


                stateChangedArray[(int)values[i]] = state;
            }

            if (updateLights)
            {
                RefreshLEDState();
            }
        }
Exemplo n.º 2
0
        public Microsoft.DirectX.DirectInput.Key GetButtonKey(ButtonEnum button)
        {
            KeyProperties value = (KeyProperties)(ButtonKeys[(int)button]);

            return(value.keyCode1);
        }
Exemplo n.º 3
0
        public SBC.Key GetButtonKey(ButtonEnum button)
        {
            KeyProperties value = (KeyProperties)(ButtonKeys[(int)button]);

            return(value.keyCode1);
        }
Exemplo n.º 4
0
 public void AddButtonKeyMapping(ButtonEnum button, Microsoft.DirectX.DirectInput.Key modifier, Microsoft.DirectX.DirectInput.Key keyCode, bool holdDown)
 {
     ButtonKeys[(int)button] = new KeyProperties(modifier, keyCode, holdDown);
 }
Exemplo n.º 5
0
 public void AddButtonKeyMapping(ButtonEnum button, SBC.Key modifier, SBC.Key keyCode, bool holdDown)
 {
     ButtonKeys[(int)button] = new KeyProperties(modifier, keyCode, holdDown);
 }