Пример #1
0
        /// <summary>
        /// Copy the source object.
        /// </summary>
        /// <param name="src">Specifies the source data.</param>
        public override void Copy(OptionalParameter src)
        {
            base.Copy(src);

            if (src is ResizeParameter)
            {
                ResizeParameter p = (ResizeParameter)src;
                m_fProb = p.prob;
                m_mode  = p.resize_mode;
                m_pad   = p.pad_mode;

                m_rgInterp = new List <InterpMode>();
                foreach (InterpMode interp in p.m_rgInterp)
                {
                    m_rgInterp.Add(interp);
                }

                m_nHeight      = p.height;
                m_nWidth       = p.width;
                m_nHeightScale = p.height_scale;
                m_nWidthScale  = p.width_scale;

                m_rgfPadValue = new List <float>();
                foreach (float fPad in p.pad_value)
                {
                    m_rgfPadValue.Add(fPad);
                }
            }
        }
Пример #2
0
        public bool Equals(SimpleVariables other)
        {
            if (other == null)
            {
                return(false);
            }

            return(CurrentLevel.Equals(other.CurrentLevel) &&
                   CurrentArea.Equals(other.CurrentArea) &&
                   Language.Equals(other.Language) &&
                   MillisecondsPerGameMinute.Equals(other.MillisecondsPerGameMinute) &&
                   LastClockTick.Equals(other.LastClockTick) &&
                   GameClockHours.Equals(other.GameClockHours) &&
                   GameClockMinutes.Equals(other.GameClockMinutes) &&
                   GameClockSeconds.Equals(other.GameClockSeconds) &&
                   TimeInMilliseconds.Equals(other.TimeInMilliseconds) &&
                   TimeScale.Equals(other.TimeScale) &&
                   TimeStep.Equals(other.TimeStep) &&
                   TimeStepNonClipped.Equals(other.TimeStepNonClipped) &&
                   FramesPerUpdate.Equals(other.FramesPerUpdate) &&
                   FrameCounter.Equals(other.FrameCounter) &&
                   OldWeatherType.Equals(other.OldWeatherType) &&
                   NewWeatherType.Equals(other.NewWeatherType) &&
                   ForcedWeatherType.Equals(other.ForcedWeatherType) &&
                   WeatherTypeInList.Equals(other.WeatherTypeInList) &&
                   WeatherInterpolationValue.Equals(other.WeatherInterpolationValue) &&
                   CameraPosition.Equals(other.CameraPosition) &&
                   CameraModeInCar.Equals(other.CameraModeInCar) &&
                   CameraModeOnFoot.Equals(other.CameraModeOnFoot) &&
                   ExtraColor.Equals(other.ExtraColor) &&
                   IsExtraColorOn.Equals(other.IsExtraColorOn) &&
                   ExtraColorInterpolation.Equals(other.ExtraColorInterpolation) &&
                   Brightness.Equals(other.Brightness) &&
                   DisplayHud.Equals(other.DisplayHud) &&
                   ShowSubtitles.Equals(other.ShowSubtitles) &&
                   RadarMode.Equals(other.RadarMode) &&
                   BlurOn.Equals(other.BlurOn) &&
                   UseWideScreen.Equals(other.UseWideScreen) &&
                   MusicVolume.Equals(other.MusicVolume) &&
                   SfxVolume.Equals(other.SfxVolume) &&
                   RadioStation.Equals(other.RadioStation) &&
                   StereoOutput.Equals(other.StereoOutput) &&
                   PadMode.Equals(other.PadMode) &&
                   InvertLook.Equals(other.InvertLook) &&
                   UseVibration.Equals(other.UseVibration) &&
                   SwapNippleAndDPad.Equals(other.SwapNippleAndDPad) &&
                   HasPlayerCheated.Equals(other.HasPlayerCheated) &&
                   AllTaxisHaveNitro.Equals(other.AllTaxisHaveNitro) &&
                   TargetIsOn.Equals(other.TargetIsOn) &&
                   TargetPosition.Equals(other.TargetPosition) &&
                   PlayerPosition.Equals(other.PlayerPosition) &&
                   TrailsOn.Equals(other.TrailsOn) &&
                   TimeStamp.Equals(other.TimeStamp) &&
                   Unknown78hPS2.Equals(other.Unknown78hPS2) &&
                   Unknown7ChPS2.Equals(other.Unknown7ChPS2) &&
                   Unknown90hPS2.Equals(other.Unknown90hPS2) &&
                   UnknownB8hPSP.Equals(other.UnknownB8hPSP) &&
                   UnknownD8hPS2.Equals(other.UnknownD8hPS2) &&
                   UnknownD9hPS2.Equals(other.UnknownD9hPS2));
        }
Пример #3
0
        public static Image <T> Image <T>(Image <T> input, Padding padding, PadMode mode,
                                          T constantValue = default(T), Allocator allocator = Allocator.Persistent)
            where T : struct
        {
            var output = default(Image <T>);

            switch (mode)
            {
            // constant is the only method supported so far
            case PadMode.Constant:
                output = Constant(input, padding, constantValue, allocator);
                break;
            }

            return(output);
        }
Пример #4
0
        /// <summary>
        /// Copy the source object.
        /// </summary>
        /// <param name="src">Specifies the source data.</param>
        public void Copy(ResizeParameter src)
        {
            m_fProb = src.prob;
            m_mode  = src.resize_mode;
            m_pad   = src.pad_mode;

            m_rgInterp = new List <InterpMode>();
            foreach (InterpMode interp in src.m_rgInterp)
            {
                m_rgInterp.Add(interp);
            }

            m_nHeight      = src.height;
            m_nWidth       = src.width;
            m_nHeightScale = src.height_scale;
            m_nWidthScale  = src.width_scale;

            m_rgfPadValue = new List <float>();
            foreach (float fPad in src.pad_value)
            {
                m_rgfPadValue.Add(fPad);
            }
        }
        private void ProcessInput(byte[] dataBytes)
        {
            DebugWrite("Data Received: ");
            DebugDump(dataBytes);

            if ((dataBytes[0] & 0xFC) == 0x28)
            {
                DebugWriteLine("iMon PAD remote button");

                uint keyCode = IMON_PAD_BUTTON;
                keyCode += (uint)((dataBytes[0] & 0x03) << 6);
                keyCode += (uint)(dataBytes[1] & 0x30);
                keyCode += (uint)((dataBytes[1] & 0x06) << 1);
                keyCode += (uint)((dataBytes[2] & 0xC0) >> 6);

                if ((_usePadSwitch) & (_remoteMode == RemoteMode.iMON))
                {
                    if (keyCode == (IMON_PAD_BUTTON + 0x50))
                    {
                        // the mouse/keyboard button was released
                        _padMode = ((_padMode == PadMode.Mouse) ? PadMode.Keyboard : PadMode.Mouse);
                        //only change modes on the release of the button
                        DebugWriteLine("RAW IMON HID REMOTE - MOUSE/KEYBOARD MODE CHANGED - NEW MODE = {0}\n", Enum.GetName(typeof(PadMode), _padMode));
                        return;
                    }
                }
                if ((keyCode & 0x01) == 0 && (dataBytes[2] & 0x40) == 0)
                {
                    RemoteEvent(keyCode, _remoteToggle != 1);
                    _remoteToggle = 1;
                }
                else
                {
                    _remoteToggle = 0;
                }
            }
            else if ((dataBytes[0] & 0xFC) == 0x68)
            {
                DebugWriteLine("ProcessInput(): iMon PAD mouse report");
                ProcessiMonMouseReport(dataBytes[0], dataBytes[1], dataBytes[2], dataBytes[3]);
            }
            else if (dataBytes[7] == 0xAE)
            {
                DebugWriteLine("MCE remote button");
                uint keyCode = IMON_MCE_BUTTON + dataBytes[3];

                RemoteEvent(keyCode, _remoteToggle != dataBytes[2]);
                _remoteToggle = dataBytes[2];
            }
            else if (dataBytes[7] == 0xBE)
            {
                DebugWriteLine("MCE Keyboard key press");
                KeyboardEvent(dataBytes[2], dataBytes[3]);
            }
            else if (dataBytes[7] == 0xCE)
            {
                DebugWriteLine("MCE Keyboard mouse move/button");
                int xSign = (dataBytes[0] & 0x01) != 0 ? 1 : -1;
                int ySign = (dataBytes[0] & 0x02) == 0 ? 1 : -1;

                int xSize = ((dataBytes[2] & 0xF0) >> 4);
                int ySize = (dataBytes[2] & 0x0F);

                bool right = ((dataBytes[3] & 0x40) != 0);
                bool left = ((dataBytes[3] & 0x20) != 0);

                MouseEvent(xSign * xSize, ySign * ySize, right, left);
            }
            else if (dataBytes[7] == 0xEE)
            {
                DebugWriteLine("Front panel buttons/volume knob");
                if (dataBytes[3] > 0x01)
                {
                    uint keyCode = IMON_PANEL_BUTTON + dataBytes[3];
                    RemoteEvent(keyCode, _remoteToggle != dataBytes[3]);
                }
                _remoteToggle = dataBytes[3];

                if (dataBytes[0] == 0x01 && _remoteHandler != null)
                    _remoteHandler(Name, IMON_VOLUME_DOWN.ToString());

                if (dataBytes[1] == 0x01 && _remoteHandler != null)
                    _remoteHandler(Name, IMON_VOLUME_UP.ToString());
            }
        }
        private void SetHid(PadMode mode)
        {
            DebugWriteLine("Force_HID_PadMode({0})", Enum.GetName(typeof(PadMode), mode));
            byte[][] modeData = new Byte[0][];

            switch (mode)
            {
                case PadMode.Keyboard:
                    modeData = SetHidPadModeKeyboard;
                    break;
                case PadMode.Mouse:
                    modeData = SetHidPadModeMouse;
                    break;
            }
            SetHid(modeData);
        }
        private void ProcessInputCommand(ref Message message)
        {
            uint dwSize = 0;

            RawInput.GetRawInputData(message.LParam, RawInput.RawInputCommand.Input, IntPtr.Zero, ref dwSize,
                                     (uint)Marshal.SizeOf(typeof(RawInput.RAWINPUTHEADER)));

            IntPtr buffer = Marshal.AllocHGlobal((int)dwSize);
            try
            {
                if (buffer == IntPtr.Zero)
                    return;

                if (
                  RawInput.GetRawInputData(message.LParam, RawInput.RawInputCommand.Input, buffer, ref dwSize,
                                           (uint)Marshal.SizeOf(typeof(RawInput.RAWINPUTHEADER))) != dwSize)
                    return;

                RawInput.RAWINPUT raw = (RawInput.RAWINPUT)Marshal.PtrToStructure(buffer, typeof(RawInput.RAWINPUT));

                #region device filtering

                // get the name of the device that generated the input message
                string deviceName = string.Empty;
                uint pcbSize = 0;
                RawInput.GetRawInputDeviceInfo(raw.header.hDevice, RawInput.RIDI_DEVICENAME, IntPtr.Zero, ref pcbSize);
                if (pcbSize > 0)
                {
                    IntPtr pData = Marshal.AllocHGlobal((int)pcbSize);
                    RawInput.GetRawInputDeviceInfo(raw.header.hDevice, RawInput.RIDI_DEVICENAME, pData, ref pcbSize);
                    deviceName = Marshal.PtrToStringAnsi(pData);
                    Marshal.FreeHGlobal(pData);
                }
                // stop processing if the device that generated the event is NOT an iMon device
                if (deviceName.Equals(string.Empty) | deviceName.Equals(""))
                {
                    return;
                }
                else
                {
                    if ((RemoteDevice > 0) & (raw.header.dwType == RawInput.RawInputType.HID))
                        if (!deviceName.Equals(RemoteDeviceName)) return;
                    if ((KeyboardDevice > 0) & (raw.header.dwType == RawInput.RawInputType.Keyboard))
                        if (!deviceName.Equals(KeyboardDeviceName)) return;
                    if ((MouseDevice > 0) & (raw.header.dwType == RawInput.RawInputType.Mouse))
                        if (!deviceName.Equals(MouseDeviceName)) return;
                }

                #endregion

                DebugWriteLine("Received Input Command ({0})", Enum.GetName(typeof(RawInput.RawInputType), raw.header.dwType));
                DebugWriteLine("RAW HID DEVICE: {0}", deviceName);

                switch (raw.header.dwType)
                {
                    case RawInput.RawInputType.HID:
                        {
                            int offset = Marshal.SizeOf(typeof(RawInput.RAWINPUTHEADER)) + Marshal.SizeOf(typeof(RawInput.RAWHID));

                            byte[] bRawData = new byte[offset + raw.hid.dwSizeHid];
                            Marshal.Copy(buffer, bRawData, 0, bRawData.Length);

                            byte[] newArray = new byte[raw.hid.dwSizeHid];
                            Array.Copy(bRawData, offset, newArray, 0, newArray.Length);

                            string RawCode = BitConverter.ToString(newArray);
                            DebugWriteLine("RAW HID DATA: {0}", RawCode);
                            // process the remote button press
                            string code = string.Empty;
                            if (((newArray[1] & 0xFC) == 0x28) & (newArray[4] == 0xB7))
                            {
                                // iMon PAD remote
                                int val = (((newArray[1] & 0x03) << 6) | (newArray[2] & 0x30) | ((newArray[2] & 0x06) << 1) |
                                           ((newArray[3] & 0xC0) >> 6));
                                code = String.Format("{0:X2}", val);
                                uint keyCode = IMON_PAD_BUTTON + (uint)val;
                                if ((_usePadSwitch) & (_remoteMode == RemoteMode.iMON))
                                {
                                    if ((keyCode == (IMON_PAD_BUTTON + 0x50)) | (keyCode == (IMON_PAD_BUTTON + 0x51)))
                                    {
                                        // the keyboard/mouse button was pressed or released
                                        if (keyCode == (IMON_PAD_BUTTON + 0x51))
                                        {
                                            // the mouse/keyboard button was released
                                            keyCode = 0;
                                            _padMode = ((_padMode == PadMode.Mouse)
                                                                    ? PadMode.Keyboard
                                                                    : PadMode.Mouse);
                                            //only change modes on the release of the button
                                            DebugWriteLine("RAW IMON HID REMOTE - MOUSE/ KEYBOARD MODE CHANGED - NEW MODE = {0}\n",
                                                           Enum.GetName(typeof(PadMode), _padMode));
                                            SetHid(_padMode);
                                        }
                                        break;
                                    }
                                }
                                if ((keyCode & 0x01) == 0)
                                {
                                    if (keyCode > 0)
                                    {
                                        RemoteEvent(keyCode, _remoteToggle != 1);
                                        _remoteToggle = 1;
                                    }
                                }
                                else
                                {
                                    _remoteToggle = 0;
                                    DebugWriteLine("iMon HID RemoteEvent: {0}, {1}\n", keyCode, "RELEASED (CONSUMED)");
                                }
                            }
                            else if (newArray[8] == 0xAE) // MCE remote button
                            {
                                uint keyCode = IMON_MCE_BUTTON + newArray[4];

                                RemoteEvent(keyCode, _remoteToggle != newArray[3]);
                                _remoteToggle = newArray[3];
                            }
                            else if (newArray[8] == 0xBE) // MCE Keyboard key press
                            {
                                KeyboardEvent(newArray[3], newArray[4]);
                            }
                            else if (newArray[8] == 0xCE) // MCE Keyboard mouse move/button
                            {
                                int xSign = (newArray[3] & 0x20) == 0 ? 1 : -1;
                                int ySign = (newArray[2] & 0x10) == 0 ? 1 : -1;

                                int xSize = (newArray[4] & 0x0F);
                                int ySize = (newArray[3] & 0x0F);

                                bool right = (newArray[4] & 0x40) != 0;
                                bool left = (newArray[4] & 0x20) != 0;

                                MouseEvent(xSign * xSize, ySign * ySize, right, left);
                            }
                            else if (newArray[8] == 0xEE) // Front panel buttons/volume knob
                            {
                                if (newArray[5] != 0x00)
                                {
                                    uint keyCode = IMON_PANEL_BUTTON + newArray[5];
                                    RemoteEvent(keyCode, _remoteToggle != newArray[4]);
                                }
                                _remoteToggle = newArray[4];

                                if (newArray[1] == 0x01)
                                    RemoteEvent(IMON_VOLUME_DOWN, true);
                                if (newArray[2] == 0x01)
                                    RemoteEvent(IMON_VOLUME_UP, true);
                                if (newArray[4] == 0x01)
                                    RemoteEvent(IMON_NAVIGATION_UP, true);
                                if (newArray[3] == 0x01)
                                    RemoteEvent(IMON_NAVIGATION_DOWN, true);
                            }
                            else if ((newArray[1] & 0xFC) == 0x68)
                            {
                                ProcessiMonMouseReport(newArray[1], newArray[2], newArray[3], newArray[4]);
                            }
                            //if (_remoteHandler != null) _remoteHandler(this.Name, code);
                            break;
                        }

                    case RawInput.RawInputType.Mouse:
                        {
                            DebugWriteLine("RAW IMON HID MOUSE - lLastX: {0}  lLastY: {1}  Buttons: {2}", raw.mouse.lLastX,
                                           raw.mouse.lLastY, raw.mouse.ulButtons);
                            // X movement is horizontal (negative towards left), y movement is vertical (negative towards top)
                            if (_padMode == PadMode.Keyboard)
                            {
                                // convert the mouse movement into direction keys
                                uint KeyMode = ((_remoteMode == RemoteMode.iMON) ? IMON_PAD_BUTTON : IMON_MCE_BUTTON);
                                uint KeyCode = 0;
                                uint KeyCode1 = 0;

                                KeyCode = (uint)TranslateMouseToKeypress(raw.mouse.lLastX, raw.mouse.lLastY);
                                if (KeyCode != 0) RemoteEvent((KeyCode + KeyMode), false);

                                KeyCode1 = 0;
                                switch (raw.mouse.ulButtons)
                                {
                                    case 1: // Left click down
                                    case 2: // Left click up
                                        KeyCode1 = IMON_PAD_BUTTON_LCLICK;
                                        break;
                                    case 4: // Right click down
                                    case 8: // Right click up
                                        KeyCode1 = IMON_PAD_BUTTON_RCLICK;
                                        break;
                                }
                                if (KeyCode1 != 0)
                                {
                                    RemoteEvent((KeyCode1 + KeyMode), false);
                                }
                                if ((KeyCode == 0) & (KeyCode1 == 0))
                                {
                                    DebugWriteLine("RAW IMON HID MOUSE - Ignoring");
                                }
                            }
                            else
                            {
                                MouseEvent(raw.mouse.lLastX, raw.mouse.lLastY, ((int)(raw.mouse.ulButtons & 0x03) > 0),
                                           ((int)(raw.mouse.ulButtons & 0x0C) > 0));
                                //if (_mouseHandler != null)
                                //    _mouseHandler(this.Name, raw.mouse.lLastX, raw.mouse.lLastY, (int)raw.mouse.ulButtons);
                            }
                            break;
                        }

                    case RawInput.RawInputType.Keyboard:
                        {
                            if (_enableKeyboardInput)
                            {
                                DebugWriteLine("RAW IMON HID KEYBOARD- CODE: {0}  FLAGS: {1}  MESSAGE: {2}", raw.keyboard.VKey,
                                               raw.keyboard.Flags, raw.keyboard.Message);
                                bool ConsumeKeypress = false;
                                bool SendToKeyboard = false;
                                uint KeyCode = 0;

                                switch (raw.keyboard.Flags)
                                {
                                    case RawInput.RawKeyboardFlags.KeyE0:
                                        DebugWriteLine(String.Format("KEYBOARD FLAG E0: {0}", raw.keyboard.MakeCode));
                                        KeyCode = 0;
                                        uint KeyBase = ((_remoteMode == RemoteMode.iMON) ? IMON_PAD_BUTTON : IMON_MCE_BUTTON);
                                        if (_remoteMode == RemoteMode.iMON)
                                        {
                                            if (raw.keyboard.VKey == 92)
                                            {
                                                KeyCode = IMON_PAD_BUTTON_WINKEY;
                                            }
                                            if (raw.keyboard.VKey == 93)
                                            {
                                                KeyCode = IMON_PAD_BUTTON_MENUKEY;
                                            }
                                        }
                                        else
                                        {
                                            if (raw.keyboard.VKey == 37)
                                            {
                                                KeyCode = IMON_MCE_BUTTON_UP;
                                            }
                                            if (raw.keyboard.VKey == 38)
                                            {
                                                KeyCode = IMON_MCE_BUTTON_LEFT;
                                            }
                                            if (raw.keyboard.VKey == 39)
                                            {
                                                KeyCode = IMON_MCE_BUTTON_RIGHT;
                                            }
                                            if (raw.keyboard.VKey == 40)
                                            {
                                                KeyCode = IMON_MCE_BUTTON_DOWN;
                                            }
                                        }
                                        if (KeyCode != 0) RemoteEvent(KeyCode + KeyBase, false);
                                        //if (_keyboardHandler != null)
                                        //  _keyboardHandler(this.Name, 0xE000 | raw.keyboard.MakeCode, true);

                                        break;

                                    case RawInput.RawKeyboardFlags.KeyE1:
                                        DebugWriteLine(String.Format("KEYBOARD FLAG E1: {0}", raw.keyboard.MakeCode));
                                        //if (_keyboardHandler != null)
                                        //  _keyboardHandler(this.Name, 0xE100, true);
                                        break;

                                    case RawInput.RawKeyboardFlags.KeyMake:
                                        //#if DEBUG
                                        //                                  DebugWriteLine("RAW IMON HID KEYBOARD CODE: {0}  FLAGS: {1}  MESSAGE: {2}", raw.keyboard.VKey, raw.keyboard.Flags, raw.keyboard.Message);
                                        //                                  Console.WriteLine("RAW IMON HID KEYBOARD CODE: {0}  FLAGS: {1}  MESSAGE: {2}  EXTRA: {3}", raw.keyboard.VKey, raw.keyboard.Flags, raw.keyboard.Message, raw.keyboard.ExtraInformation);
                                        //#endif
                                        if (_keyboardHandler != null)
                                        {
                                            KeyCode = 0;
                                            // convert the keyboard code into an iMon code
                                            if ((raw.keyboard.VKey == 16) | (raw.keyboard.VKey == 17) | (raw.keyboard.VKey == 18))
                                            {
                                                ModifierState.LastKeydownWasShift = false;
                                                ModifierState.LastKeyupWasShift = false;
                                                ModifierState.LastKeydownWasCtrl = false;
                                                ModifierState.LastKeyupWasCtrl = false;
                                                ModifierState.LastKeydownWasAlt = false;
                                                ModifierState.LastKeyupWasAlt = false;
                                                if (raw.keyboard.VKey == 16)
                                                {
                                                    ModifierState.ShiftOn = true;
                                                    ModifierState.LastKeydownWasShift = true;
                                                }
                                                if (raw.keyboard.VKey == 17)
                                                {
                                                    ModifierState.CtrlOn = true;
                                                    ModifierState.LastKeydownWasCtrl = true;
                                                }
                                                if (raw.keyboard.VKey == 18)
                                                {
                                                    ModifierState.AltOn = true;
                                                    ModifierState.LastKeydownWasAlt = true;
                                                }
                                                ConsumeKeypress = true;
                                            }
                                            else
                                            {
                                                if (_remoteMode == RemoteMode.iMON)
                                                {
                                                    if (ConvertVKeyToiMonKeyCode((Keyboard.VKey)raw.keyboard.VKey, ModifierState) != 0)
                                                    {
                                                        KeyCode = IMON_PAD_BUTTON +
                                                                  ConvertVKeyToiMonKeyCode((Keyboard.VKey)raw.keyboard.VKey, ModifierState);
                                                    }
                                                    else
                                                    {
                                                        KeyCode = raw.keyboard.VKey;
                                                        SendToKeyboard = true;
                                                    }
                                                    ModifierState.LastKeydownWasShift = false;
                                                    ModifierState.LastKeydownWasCtrl = false;
                                                    ModifierState.LastKeydownWasAlt = false;
                                                }
                                                else
                                                {
                                                    KeyCode = IMON_MCE_BUTTON +
                                                              ConvertVKeyToiMonMceKeyCode((Keyboard.VKey)raw.keyboard.VKey, ModifierState);
                                                    ModifierState.LastKeydownWasShift = false;
                                                    ModifierState.LastKeydownWasCtrl = false;
                                                    ModifierState.LastKeydownWasAlt = false;
                                                }
                                            }
                                            if (!ConsumeKeypress & !SendToKeyboard)
                                            {
                                                RemoteEvent(KeyCode, false);
                                            }
                                            else if (!ConsumeKeypress)
                                            {
                                                _keyboardHandler(Name, (int)KeyCode, false);
                                            }
                                            else
                                            {
                                                DebugWriteLine("CONSUMED HID KEYBOARD - CODE: {0}  FLAGS: {1}  MESSAGE: {2}", raw.keyboard.VKey,
                                                               raw.keyboard.Flags, raw.keyboard.Message);
                                            }
                                            //_keyboardHandler(this.Name, (int)KeyCode, false);
                                        }
                                        break;

                                    case RawInput.RawKeyboardFlags.KeyBreak:
                                        KeyCode = 0;
                                        ConsumeKeypress = false;
                                        SendToKeyboard = false;
                                        //convert the keyboard code into an iMon code
                                        if ((raw.keyboard.VKey == 16) | (raw.keyboard.VKey == 17) | (raw.keyboard.VKey == 18))
                                        {
                                            ModifierState.LastKeydownWasShift = false;
                                            ModifierState.LastKeyupWasShift = false;
                                            ModifierState.LastKeydownWasCtrl = false;
                                            ModifierState.LastKeyupWasCtrl = false;
                                            ModifierState.LastKeydownWasAlt = false;
                                            ModifierState.LastKeyupWasAlt = false;
                                            if (raw.keyboard.VKey == 16)
                                            {
                                                ModifierState.ShiftOn = false;
                                                ModifierState.LastKeyupWasShift = true;
                                            }
                                            if (raw.keyboard.VKey == 17)
                                            {
                                                ModifierState.CtrlOn = false;
                                                ModifierState.LastKeyupWasAlt = true;
                                            }
                                            if (raw.keyboard.VKey == 18)
                                            {
                                                ModifierState.AltOn = false;
                                                ModifierState.LastKeyupWasAlt = true;
                                            }
                                            ConsumeKeypress = true;
                                        }
                                        else
                                        {
                                            if (_remoteMode == RemoteMode.iMON)
                                            {
                                                if (ConvertVKeyToiMonKeyCode((Keyboard.VKey)raw.keyboard.VKey, ModifierState) != 0)
                                                {
                                                    KeyCode = IMON_PAD_BUTTON +
                                                              ConvertVKeyToiMonKeyCode((Keyboard.VKey)raw.keyboard.VKey, ModifierState);
                                                }
                                                else
                                                {
                                                    KeyCode = raw.keyboard.VKey;
                                                    //_keyboardHandler(this.Name, (int)KeyCode, true);
                                                    SendToKeyboard = true;
                                                }
                                                ModifierState.LastKeyupWasShift = false;
                                                ModifierState.LastKeyupWasCtrl = false;
                                                ModifierState.LastKeyupWasAlt = false;
                                            }
                                            else
                                            {
                                                KeyCode = IMON_MCE_BUTTON +
                                                          ConvertVKeyToiMonMceKeyCode((Keyboard.VKey)raw.keyboard.VKey, ModifierState);
                                                ModifierState.LastKeyupWasShift = false;
                                                ModifierState.LastKeyupWasCtrl = false;
                                                ModifierState.LastKeyupWasAlt = false;
                                            }
                                        }
                                        if (!ConsumeKeypress & !SendToKeyboard)
                                        {
                                            RemoteEvent(KeyCode, false);
                                        }
                                        else if (!ConsumeKeypress)
                                        {
                                            _keyboardHandler(Name, (int)KeyCode, true);
                                        }
                                        else
                                        {
                                            DebugWriteLine("CONSUMED HID KEYBOARD - CODE: {0}  FLAGS: {1}  MESSAGE: {2}\n", raw.keyboard.VKey,
                                                           raw.keyboard.Flags, raw.keyboard.Message);
                                        }
                                        break;

                                    case RawInput.RawKeyboardFlags.TerminalServerSetLED:
                                        DebugWriteLine("RAW IMON HID KEYBOARD - TerminalServerSetLED - CODE: {0}  FLAGS: {1}  MESSAGE: {2}",
                                                       raw.keyboard.VKey, raw.keyboard.Flags, raw.keyboard.Message);
                                        break;

                                    case RawInput.RawKeyboardFlags.TerminalServerShadow:
                                        DebugWriteLine("RAW IMON HID KEYBOARD - TerminalServerShadow - CODE: {0}  FLAGS: {1}  MESSAGE: {2}",
                                                       raw.keyboard.VKey, raw.keyboard.Flags, raw.keyboard.Message);
                                        break;
                                }
                            }
                            else DebugWriteLine("RAW IMON HID KEYBOARD (ignoring) - CODE: {0}  FLAGS: {1}  MESSAGE: {2}",
                                                raw.keyboard.VKey, raw.keyboard.Flags, raw.keyboard.Message);
                            break;
                        }
                }
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
        }
        /// <summary>
        /// Loads the settings.
        /// </summary>
        private void LoadSettings()
        {
            DebugWriteLine("LoadSettings()");
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(ConfigurationFile);

                _remoteMode = (RemoteMode)Enum.Parse(typeof(RemoteMode), doc.DocumentElement.Attributes["RemoteMode"].Value);
                _padMode = (PadMode)Enum.Parse(typeof(PadMode), doc.DocumentElement.Attributes["PadMode"].Value);

                _enableRemoteInput = bool.Parse(doc.DocumentElement.Attributes["EnableRemoteInput"].Value);
                _usePadSwitch = bool.Parse(doc.DocumentElement.Attributes["UsePadSwitch"].Value);
                _useSystemRatesRemote = bool.Parse(doc.DocumentElement.Attributes["UseSystemRatesRemote"].Value);
                _remoteFirstRepeat = int.Parse(doc.DocumentElement.Attributes["RemoteFirstRepeat"].Value);
                _remoteHeldRepeats = int.Parse(doc.DocumentElement.Attributes["RemoteHeldRepeats"].Value);

                _enableKeyboardInput = bool.Parse(doc.DocumentElement.Attributes["EnableKeyboardInput"].Value);
                _useSystemRatesKeyboard = bool.Parse(doc.DocumentElement.Attributes["UseSystemRatesKeyboard"].Value);
                _keyboardFirstRepeat = int.Parse(doc.DocumentElement.Attributes["KeyboardFirstRepeat"].Value);
                _keyboardHeldRepeats = int.Parse(doc.DocumentElement.Attributes["KeyboardHeldRepeats"].Value);
                _handleKeyboardLocally = bool.Parse(doc.DocumentElement.Attributes["HandleKeyboardLocally"].Value);

                _enableMouseInput = bool.Parse(doc.DocumentElement.Attributes["EnableMouseInput"].Value);
                _handleMouseLocally = bool.Parse(doc.DocumentElement.Attributes["HandleMouseLocally"].Value);
                _mouseSensitivity = double.Parse(doc.DocumentElement.Attributes["MouseSensitivity"].Value);
                _keyPadSensitivity = int.Parse(doc.DocumentElement.Attributes["KeyPadSensitivity"].Value);
            }
            catch (Exception ex)
            {
                DebugWriteLine(ex.ToString());
                _remoteMode = RemoteMode.iMON;
                _padMode = PadMode.Keyboard;

                _enableRemoteInput = true;
                _useSystemRatesRemote = false;
                _remoteFirstRepeat = 400;
                _remoteHeldRepeats = 250;

                _enableKeyboardInput = true;
                _useSystemRatesKeyboard = true;
                _keyboardFirstRepeat = 350;
                _keyboardHeldRepeats = 0;
                _handleKeyboardLocally = true;

                _enableMouseInput = true;
                _handleMouseLocally = true;
                _mouseSensitivity = 1.0d;
            }
        }