• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / Key2Joy / 6738508468

02 Nov 2023 09:38PM UTC coverage: 43.012% (-0.8%) from 43.795%
6738508468

Pull #66

github

web-flow
Merge b13824648 into 6a3d02880
Pull Request #66: Bugfix recently discovered input bugs

754 of 2413 branches covered (0.0%)

Branch coverage included in aggregate %.

203 of 203 new or added lines in 9 files covered. (100.0%)

3859 of 8312 relevant lines covered (46.43%)

11968.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

18.42
/Core/Key2Joy.Core/LowLevelInput/SimulatedGamePad/SimulatedGamePad.cs
1
using System;
2
using SimWinInput;
3

4
namespace Key2Joy.LowLevelInput.SimulatedGamePad;
5

6
/// <summary>
7
/// Implementation based on https://github.com/DavidRieman/SimWinInput
8
/// </summary>
9
public class SimulatedGamePad : ISimulatedGamePad
10
{
11
    private const string GAMEPAD_NAME = "Simulated";
12

13
    /// <inheritdoc />
14
    public int Index { get; private set; }
36✔
15

16
    private bool isPluggedIn = false;
17
    private readonly IGamePadInfo gamePadInfo;
18

19
    private object stateLock = new();
36✔
20

21
    public SimulatedGamePad(int index)
36✔
22
    {
23
        this.Index = index;
36✔
24
        this.gamePadInfo = new GamePadInfo(index, GAMEPAD_NAME);
36✔
25
    }
36✔
26

27
    public IGamePadInfo GetInfo()
28
        => this.gamePadInfo;
×
29

30
    /// <inheritdoc />
31
    public void PlugIn()
32
    {
33
        SimGamePad.Instance.PlugIn(this.Index);
×
34
        this.isPluggedIn = true;
×
35

36
        // Ensure the state starts reset fixes problem where other (real) gamepad may get button stuck
37
        this.ResetState();
×
38
    }
×
39

40
    /// <inheritdoc />
41
    public bool GetIsPluggedIn()
42
        => this.isPluggedIn;
8✔
43

44
    /// <inheritdoc />
45
    public void Unplug()
46
    {
47
        SimGamePad.Instance.Unplug(this.Index);
×
48
        this.isPluggedIn = false;
×
49
    }
×
50

51
    /// <inheritdoc />
52
    public void Use(GamePadControl control, int holdTimeMS = 50)
53
    {
54
        SimGamePad.Instance.Use(control, this.Index, holdTimeMS);
×
55
        this.gamePadInfo.OnActivityOccurred();
×
56
    }
×
57

58
    /// <inheritdoc />
59
    public void SetControl(GamePadControl control)
60
    {
61
        SimGamePad.Instance.SetControl(control, this.Index);
×
62
        this.gamePadInfo.OnActivityOccurred();
×
63
    }
×
64

65
    /// <inheritdoc />
66
    public void ReleaseControl(GamePadControl control)
67
    {
68
        SimGamePad.Instance.ReleaseControl(control, this.Index);
×
69
        this.gamePadInfo.OnActivityOccurred();
×
70
    }
×
71

72
    /// <inheritdoc />
73
    public void AccessState(Func<SimulatedGamePadState, StateAccessorResult> stateAccessor)
74
    {
75
        // Commented, because as expected this freezes the app up when
76
        // everyone has to wait for the lock to be released. And it didn't
77
        // fix #61 like I hoped it would.
78
        //lock (this.stateLock)
79
        {
80
            var state = SimGamePad.Instance.State[this.Index];
×
81

82
            if (stateAccessor(state) == StateAccessorResult.Unchanged)
×
83
            {
84
                return;
×
85
            }
86

87
            SimGamePad.Instance.Update(this.Index);
×
88
            this.gamePadInfo.OnActivityOccurred();
×
89
        }
90
    }
×
91

92
    /// <inheritdoc />
93
    public void ResetState()
94
        => this.AccessState((state) =>
×
95
        {
×
96
            state.Reset();
×
97

×
98
            return StateAccessorResult.Changed;
×
99
        });
×
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc