private void poll_Tick(object o)
        {
            lock (pollLock)
            {
                HashSet<Action<DirectInputData>> action;
                BufferedDataCollection queue = null;

                try
                {
                    _device.Poll();
                    queue = _device.GetBufferedData();
                }
                catch
                {
                    Debug.Print("DirectInputKeyboard::poll_tick exception");
                    _pollTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    if (OnError != null)
                        OnError(this, EventArgs.Empty);

                    return;
                }

                if (queue != null)
                {
                    foreach (BufferedData data in queue)
                    {
                        Key dataType = (Key)data.Offset;
                        KeyState state = (KeyState)data.Data;

                        DirectInputData keyData = new DirectInputData()
                        {
                            Value = data.Data,
                            KeyboardKey = dataType,
                            Type = DIDataType.Keyboard,
                            DeviceName = Name

                        };
                        CustomEventArgs<DirectInputData> eventArg = new CustomEventArgs<DirectInputData>(keyData);

                        _actionMap.TryGetValue(dataType, out action);

                        if (action != null)
                            action.ToList().ForEach(a => a(keyData));

                        if (state == KeyState.Down && OnKeyDown != null)
                            OnKeyDown(this, eventArg);

                        if (state == KeyState.Up)
                        {
                            if (OnKeyUp != null)
                                OnKeyUp(this, eventArg);
                            if (OnKeyPress != null)
                                OnKeyPress(this, eventArg);
                        }

                    }
                }
            }
              
        }
Exemple #2
0
        public void ProcessData( DirectInputData data )
        {
            HotKey hotkey = null;
            var hotKeysByType = Keys.Where( hk => hk.Key.Type == data.Type );

            if( hotKeysByType.Count() <= 0 )
                return;


            switch (data.Type)
            {
                case DIDataType.Joystick:
                    hotkey = hotKeysByType.FirstOrDefault(hk => hk.Key.JoystickOffset == data.JoystickOffset);
                    break;

                case DIDataType.Mouse:
                    hotkey = hotKeysByType.FirstOrDefault(hk => hk.Key.MouseOffset == data.MouseOffset);
                    break;

                case DIDataType.Keyboard:
                    hotkey = hotKeysByType.FirstOrDefault(hk => hk.Key.KeyboardKey == data.KeyboardKey);
                    break;
            }

            if (hotkey == null)
                return;

            switch (hotkey.HotKeyType)
            {
                case HotKeyType.NextProfile:
                    if (OnNextProfile != null) OnNextProfile(this, EventArgs.Empty);
                    break;
                case HotKeyType.PrevProfile:
                    if (OnPrevProfile != null) OnPrevProfile(this, EventArgs.Empty);
                    break;
                case HotKeyType.DecSensitivity:
                    if (OnDecSensitivity != null) OnDecSensitivity(this, EventArgs.Empty);
                    break;
                case HotKeyType.IncSensitivity:
                    if (OnIncSensitivity != null) OnIncSensitivity(this, EventArgs.Empty);
                    break;
                case HotKeyType.SetLowSensitivity:
                    if (OnSetLowSensitivity != null) OnSetLowSensitivity(this, new HotKeyArgs(hotkey));
                    break;
                case HotKeyType.SetMediumSensitivity:
                    if (OnSetMediumSensitivity != null) OnSetMediumSensitivity(this, new HotKeyArgs(hotkey));
                    break;
                case HotKeyType.SetHighSensitivity:
                    if (OnSetHighSensitivity != null) OnSetHighSensitivity(this, new HotKeyArgs(hotkey));
                    break;
            }
        }
        void JoystickTester_HandleCreated(object sender, EventArgs e)
        {

            Paint += new PaintEventHandler(JoystickTester_Paint);
            var defaultAxis = new DirectInputData();
            PhysicalAxisPitch = defaultAxis;
            PhysicalAxisRoll = defaultAxis;
            PhysicalAxisRudder = defaultAxis;

            VirtualAxisPitch = defaultAxis;
            VirtualAxisRoll = defaultAxis;
            VirtualAxisRudder = defaultAxis;

            Invalidate();
           
        }
        void JoystickTester_Paint(object sender, PaintEventArgs e)
        {

            var dashValues = new Single[] { 1, 1 };
            var dashCircleValues = new Single[] { 5, 5 };
            var smallestSide = Math.Min(Size.Width - Margin.Left - Margin.Right, Size.Height - Margin.Top - Margin.Bottom);
            var drawArea = new Rectangle(Margin.Left, Margin.Top, smallestSide, smallestSide);
            var topLeft = new Point(Margin.Left, Margin.Top);
            var topMiddle = new Point(smallestSide / 2 + Margin.Left, Margin.Top);
            var topRight = new Point(smallestSide + Margin.Left, Margin.Top);
            var leftMiddle = new Point(Margin.Left, smallestSide / 2 + Margin.Top);
            var bottomLeft = new Point(Margin.Left, smallestSide + Margin.Top);
            var bottomMiddle = new Point(smallestSide / 2 + Margin.Left, smallestSide + Margin.Top);
            var bottomRight = new Point(smallestSide + Margin.Left, smallestSide + Margin.Top);
            var rightMiddle = new Point(smallestSide + Margin.Left, smallestSide / 2 + Margin.Top);
            var center = new Point(smallestSide / 2 + Margin.Left, smallestSide / 2 + Margin.Top);
            var green = 80;
            var gridPen = new Pen(Color.FromArgb(0, green, 0));
            var pointLeftRudder = new Point(Margin.Left, Size.Height - 20);
            var pointRightRudder = new Point(smallestSide + Margin.Left, Size.Height - 20);
            var rudderWidth = pointRightRudder.X - pointLeftRudder.X;
            if (virtualCross == null)
            {

                virtualCross = new Bitmap(RETICLE_SIZE, RETICLE_SIZE);
                virtualLine = new Bitmap(RETICLE_SIZE, RETICLE_SIZE);
                physicalCross = new Bitmap(RETICLE_SIZE, RETICLE_SIZE);
                physicalLine = new Bitmap(RETICLE_SIZE, RETICLE_SIZE);

                var vcG = Graphics.FromImage(virtualCross);
                var vlG = Graphics.FromImage(virtualLine);
                var pcG = Graphics.FromImage(physicalCross);
                var plG = Graphics.FromImage(physicalLine);


                HandleBounds = new Rectangle(topLeft.X - RETICLE_SIZE / 2, topLeft.Y - RETICLE_SIZE / 2, smallestSide, smallestSide);
                RudderBounds = new Rectangle(pointLeftRudder.X - RETICLE_SIZE / 2, pointLeftRudder.Y - RETICLE_SIZE / 2, rudderWidth, RETICLE_SIZE);
                
                var p0 = new Point(0, 0);

                var pen = new Pen(Color.FromArgb(0, 150, 0));
                DrawReticle(plG, ReticleShape.VerticalLine, p0, pen);
                DrawReticle(pcG, ReticleShape.Cross, p0, pen);

                pen = new Pen(Color.FromArgb(0, 255, 0));
                    
                DrawReticle(vlG, ReticleShape.VerticalLine, p0, pen);
                DrawReticle(vcG, ReticleShape.Cross, p0, pen);

                vcG.Dispose();
                vlG.Dispose();
                pcG.Dispose();
                plG.Dispose();
                pen.Dispose();
                gridPen.Dispose();

                var centerPoint = new Point(center.X - RETICLE_SIZE / 2, center.Y - RETICLE_SIZE / 2);
                var centerAxis = new DirectInputData() {Max = 1000, Min = -1000, Value = 0};
                PhysicalAxisPitch = centerAxis;
                PhysicalAxisRoll = centerAxis;
                PhysicalAxisRudder = centerAxis;
                VirtualAxisPitch = centerAxis;
                VirtualAxisRoll = centerAxis;
                VirtualAxisRudder = centerAxis;

            }

            if( ShowPhysicalHandle )
                e.Graphics.DrawImage(physicalCross, PhysicalHandleLocation);
            if( ShowPhysicalRudder )
                e.Graphics.DrawImage(physicalLine, PhysicalRudderLocation);

            if( ShowVirtualHandle)
                e.Graphics.DrawImage(virtualCross, VirtualHandleLocation);

            if( ShowVirtualRudder )
                e.Graphics.DrawImage(virtualLine, VirtualRudderLocation);

            //invalidateRegion.Union(new Rectangle(VirtualHandleLocation, new Size(RETICLE_SIZE, RETICLE_SIZE)));
            //invalidateRegion.Union(new Rectangle(VirtualRudderLocation, new Size(RETICLE_SIZE, RETICLE_SIZE)));
            //invalidateRegion.Union(new Rectangle(PhysicalHandleLocation, new Size(RETICLE_SIZE, RETICLE_SIZE)));
            //invalidateRegion.Union(new Rectangle(PhysicalRudderLocation, new Size(RETICLE_SIZE, RETICLE_SIZE)));
        }
 private int CoordByAxisValue(DirectInputData value, int coord, int bound)
 {
     int newCoord = (int)Utils.PTop(bound, value.Value - value.Min, value.Max - value.Min);
     return newCoord;
 }
        private void poll_Tick(object o)
        {
            lock (pollLock)
            {
                HashSet<Action<DirectInputData>> action;
                BufferedDataCollection queue = null;

                try
                {
                    _device.Poll();
                    queue = _device.GetBufferedData();
                }
                catch
                {
                    Debug.Print("DirectInputMouse::poll_tick exception");
                    _pollTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    if (OnError != null)
                        OnError(this, EventArgs.Empty);

                    return;
                }

                if (queue != null)
                {
                    foreach (BufferedData data in queue)
                    {
                        MouseOffset dataType = (MouseOffset)data.Offset;

                        var curValue = data.Data;

                        if (dataType < MouseOffset.Button0)
                        {
                            curValue = CurrentValue.FirstOrDefault(m => m.Key == dataType).Value;
                            var delta = (int)((float)data.Data * (float)Sensitivity[dataType] / 10.0f);
                            if (curValue + delta > 32767)
                                curValue = 32767;
                            else if (curValue + delta < -32767)
                                curValue = -32767;
                            else
                                curValue += delta;

                            CurrentValue[dataType] = curValue;
                        }
                        DirectInputData mouseData = new DirectInputData()
                        {
                            Value = curValue,
                            MouseOffset = dataType,
                            Type = DIDataType.Mouse,
                            DeviceName = Name
                        };

                        CustomEventArgs<DirectInputData> eventArg = new CustomEventArgs<DirectInputData>(mouseData);

                        _actionMap.TryGetValue(dataType, out action);

                        if (action != null)
                            action.ToList().ForEach(a => { if (a != null) a(mouseData); });

                        if (dataType >= MouseOffset.Button0)
                        {
                            if ((KeyState)data.Data == KeyState.Down && OnButtonDown != null)
                                OnButtonDown(this, eventArg);

                            if ((KeyState)data.Data == KeyState.Up)
                            {
                                if (OnButtonUp != null)
                                    OnButtonUp(this, eventArg);
                                if (OnButtonPress != null)
                                    OnButtonPress(this, eventArg);
                            }

                        }
                        else
                        {
                            //Mouse axis
                        }


                    }
                }
            }
        }
 private void emptyAction(DirectInputData joyData) {}
        private void poll_Tick(object o)
        {
            if (!Acquired)
                return;
            
            lock (pollLock)
            {
                HashSet<Action<DirectInputData>> action;
                AxisFilterMedian filter;
                BufferedDataCollection queue = null;

                try
                {
                    _device.Poll();
                    queue = _device.GetBufferedData();                    

                    if (queue != null)
                    {
                        foreach (BufferedData data in queue)
                        {
                            JoystickOffset dataType = (JoystickOffset)data.Offset;

                            DirectInputData joyData = new DirectInputData()
                            {
                                Value = data.Data,
                                JoystickOffset = dataType,
                                Type = DIDataType.Joystick,
                                DeviceName = Name
                            };

                            var eventArgs = new CustomEventArgs<DirectInputData>(joyData);

                            _actionMap.TryGetValue(dataType, out action);

                            //Axis
                            if (dataType <= JoystickOffset.PointOfView3)
                            {
                                _axisFilters.TryGetValue(dataType, out filter);

/*                                if (filter != null && filter.Noise != null && eventArgs.Data.Value != MinAxisValue && eventArgs.Data.Value != MaxAxisValue)
                                {
                                    eventArgs.Data.Value = (int)filter.Correct((double)eventArgs.Data.Value);
                                    Debug.Print(eventArgs.Data.Value.ToString());
                                }
*/
                                if (filter != null && filter.Length > 0)
                                {
                                    if (filter.IsFilled && eventArgs.Data.Value != MinAxisValue && eventArgs.Data.Value != MaxAxisValue)
                                    {
                                        eventArgs.Data.Value = filter.Add((short)eventArgs.Data.Value);
                                    }
                                    else
                                    {
                                        filter.Add((short)eventArgs.Data.Value);
                                    }
                                }
                                eventArgs.Data.Min = MinAxisValue;
                                eventArgs.Data.Max = MaxAxisValue;

                                if (OnAxisChange != null)
                                    OnAxisChange(this, eventArgs);
                            }
                            else //Button
                            {
                                if (joyData.Value == (int)KeyState.Up)
                                {
                                    if (OnButtonUp != null)
                                        OnButtonUp(this, eventArgs);
                                    if (OnButtonPress != null)
                                        OnButtonPress(this, eventArgs);
                                }
                                else if (joyData.Value == (int)KeyState.Down)
                                {
                                    if (OnButtonDown != null)
                                        OnButtonDown(this, eventArgs);
                                }
                            }
                            if (action != null)
                                action.ToList().ForEach(a => a(eventArgs.Data));
                        }
                    }
                }
                catch
                {
                    Acquired = false;
                    Debug.Print("Joystick poll tick exception");
                    _pollTimer.Change(Timeout.Infinite, Timeout.Infinite);
                    if (OnError != null)
                        OnError(this, EventArgs.Empty);
                    return;
                }

            }
        }
Exemple #9
0
 private void ActionSetTesterPhysicalRZ(DirectInputData data)
 {
     Utils.SetProperty<JoystickTester, DirectInputData>(joystickTester, "PhysicalAxisRudder", data);
 }
Exemple #10
0
 private void ActionSetTesterVirtualRZ(DirectInputData data)
 {
     Utils.SetProperty<JoystickTester, DirectInputData>(joystickTester, "VirtualAxisRudder", data);
     Utils.SetProperty<Label, String>(labelYawPercent, "Text", data.PercentValue.ToString() + "%");
 }
Exemple #11
0
        private void ActionSetVJoy(DirectInputData data)
        {
            if (timerTest.Enabled)
                return;
            if (data == null)
                return;

            String sourceDeviceName = data.DeviceName;
            String sourceAxisName = String.Empty;
            ProfileTab pTab = null;

            switch (data.Type)
            {
                case DIDataType.Joystick:
                        sourceAxisName = DIUtils.Name(data.JoystickOffset);
                    break;
                case DIDataType.Mouse:
                        sourceAxisName = DIUtils.Name(data.MouseOffset);
                    break;

            }
            if (String.IsNullOrEmpty(sourceAxisName))
                return;

            pTab = _currentProfile.Tabs.ToList().Where(t => t.SourceDevice == sourceDeviceName && t.SourceAxis == sourceAxisName).FirstOrDefault();

            if (pTab == null)
                return;

            var virtualDevice = _deviceManager.Joysticks.ToList().FirstOrDefault(
                gc => gc.Type == DeviceType.Virtual && gc.Name == pTab.DestinationDevice);

            if (virtualDevice == null)
                return;

            //Debug.Print("{0}", data.Value);

            var destAxis = DIUtils.JoyID(pTab.DestinationAxis);


            BezierCurvePoints curvePoints = pTab.CurvePoints;
            int newValue = data.Value;
            if (curvePoints != null)
            {
                float y = curvePoints.GetY(Utils.PTop(1.0f, Math.Abs(data.Value), 32767.0f));
                switch (curvePoints.CurveResponseType)
                {
                    case CurveResponseType.Multiplier:
                        newValue = (int)((float)data.Value * y);
                        //Debug.Print(String.Format("y: {0}, value: {1}", y, newValue));
                        break;
                    case CurveResponseType.Values:
                        newValue = (int)(y * 32767.0f * (data.Value < 0 ? -1 : 1));
                        break;
                }
            }
            
           

            if (pTab.Correction != 0)
            {
                var c = (int)(32767.0f * pTab.Correction / 100.0f);

                if (pTab.PreserveAxisRange)
                {
                    newValue = (int)((32767.0f - (newValue<c?-1:1) * c) * newValue / 32767.0f + c);
                }
                else
                {
                    newValue += c;
                }
            }
            
            
            if (newValue < -32767)
                newValue = -32767;
            else if (newValue > 32767)
                newValue = 32767;

            virtualDevice.Set(destAxis, newValue);
            if (_settings.enableJoystickServer)
            {
                try
                {
                    netServer.SendToAll(new JoystickState() { n = destAxis.ToString(), v = newValue });
                }
                catch { }
            }

        }
Exemple #12
0
 private void emptyAction(DirectInputData d) { }
Exemple #13
0
        private void ActionMouseProfileHotKey(DirectInputData data)
        {
            lock (lockHotMouse)
            {
                if (ProfileComboFocused)
                    return;

                var profile = _profileManager.Profiles.FirstOrDefault(
                    p => p.HotKeyMouseName == data.DeviceName && p.MouseHotKey == data.MouseOffset.ToString());

                if (profile != null && _currentProfile.Title != profile.Title)
                    Utils.CallMethod<Form>(this, "SetCurrentProfile", profile.Title);
            }
        }