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

luttje / Key2Joy / 6602636543

22 Oct 2023 08:16AM UTC coverage: 44.104% (-8.4%) from 52.519%
6602636543

Pull #50

github

web-flow
Merge cf342a7b3 into 14b7ce9a7
Pull Request #50: Add XInput in preparation for gamepad triggers + add xmldoc

764 of 2383 branches covered (0.0%)

Branch coverage included in aggregate %.

3060 of 3060 new or added lines in 106 files covered. (100.0%)

3896 of 8183 relevant lines covered (47.61%)

15812.68 hits per line

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

5.26
/Core/Key2Joy.Core/Mapping/Actions/Input/MouseButtonAction.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Threading.Tasks;
4
using Key2Joy.Contracts.Mapping;
5
using Key2Joy.Contracts.Mapping.Actions;
6
using Key2Joy.Contracts.Mapping.Triggers;
7
using Key2Joy.LowLevelInput;
8

9
namespace Key2Joy.Mapping.Actions.Input;
10

11
[Action(
12
    Description = "Mouse Button Simulation",
13
    Visibility = MappingMenuVisibility.Never,
14
    NameFormat = "{1} {0} on Mouse",
15
    GroupName = "Mouse Simulation",
16
    GroupImage = "mouse"
17
)]
18
public class MouseButtonAction : CoreAction, IPressState, IProvideReverseAspect
19
{
20
    public Mouse.Buttons Button { get; set; }
×
21
    public PressState PressState { get; set; }
×
22

23
    public MouseButtonAction(string name)
24
        : base(name)
7✔
25
    {
26
    }
7✔
27

28
    /// <inheritdoc/>
29
    public void MakeReverse(AbstractMappingAspect aspect)
30
        => CommonReverseAspect.MakeReversePressState(this, aspect);
×
31

32
    public static Mouse.Buttons[] GetAllButtons()
33
    {
34
        var allEnums = Enum.GetValues(typeof(Mouse.Buttons));
×
35
        List<Mouse.Buttons> buttons = new();
×
36

37
        // Skip the enumerations that are zero
38
        foreach (var buttonEnum in allEnums)
×
39
        {
40
            if ((short)buttonEnum == 0)
×
41
            {
42
                continue;
43
            }
44

45
            buttons.Add((Mouse.Buttons)buttonEnum);
×
46
        }
47

48
        return buttons.ToArray();
×
49
    }
50

51
    /// <markdown-doc>
52
    /// <parent-name>Input</parent-name>
53
    /// <path>Api/Input</path>
54
    /// </markdown-doc>
55
    /// <summary>
56
    /// Simulate pressing or releasing (or both) mouse buttons.
57
    /// </summary>
58
    /// <param name="button">Button to simulate</param>
59
    /// <param name="pressState">Action to simulate</param>
60
    /// <name>Mouse.Simulate</name>
61
    [ExposesScriptingMethod("Mouse.Simulate")]
62
    public async void ExecuteForScript(Mouse.Buttons button, PressState pressState)
63
    {
64
        this.Button = button;
×
65
        this.PressState = pressState;
×
66

67
        await this.Execute();
×
68
    }
×
69

70
    public override async Task Execute(AbstractInputBag inputBag = null)
71
    {
72
        if (this.PressState == PressState.Press)
×
73
        {
74
            SimulatedMouse.PressButton(this.Button);
×
75
        }
76
        else if (this.PressState == PressState.Release)
×
77
        {
78
            SimulatedMouse.ReleaseButton(this.Button);
×
79
        }
80
    }
×
81

82
    public override string GetNameDisplay() => this.Name.Replace("{0}", Enum.GetName(typeof(Mouse.Buttons), this.Button))
×
83
            .Replace("{1}", Enum.GetName(typeof(Mouse.Buttons), this.PressState));
×
84

85
    public override bool Equals(object obj)
86
    {
87
        if (obj is not MouseButtonAction action)
×
88
        {
89
            return false;
×
90
        }
91

92
        return action.Button == this.Button
×
93
            && action.PressState == this.PressState;
×
94
    }
95
}
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