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

luttje / Key2Joy / 6602669847

22 Oct 2023 08:23AM UTC coverage: 44.094% (-8.4%) from 52.519%
6602669847

push

github

web-flow
Add XInput in preparation for gamepad triggers + add xmldoc (#50)

* Add XInput in preparation for gamepad triggers + add xmldoc

* add parent-child relation between mapped options

* add remove child mappings option + remove debug context menu

* x86 > AnyCPU (gives more sensible errors in WinForms Designer) - Fixed Designer failing on MappingForm

* Fix polling gamepad

* Add gamepad input trigger and config control + Fix mapping list not updating correctly

* remove broken and quite useless test

* update readme with warning regarding #46 + update readme special thanks

* add warning on same gamepad id trigger and action

* attempt to give github actions more time before timeout (tests sometimes fail)

* use current default mapping profile from app (so we dont have to copy it to tests everytime manually)

* Add gamepad button trigger

* Add multi-property edit mode

* Show physical gamepad connection warning

* give even more time for tests so they dont fail

* Block arming mappings if simulated gamepad index collides with physical gamepad

* Cleanup + add GamePad Trigger Trigger

* Fix combined trigger remove not working

* Separate stick action and allow custom scaling

* improve stick feeling

* fix parent picker

* update default mappings

* add trigger and try work out conflicts between physical and simulated devices (no luck yet)

* Fix simulated gamepad recognized as physical

* Show gamepad devices in UI

* fix mapping form + add more multi-edit type support

* make reverse mapping tool more useful

* easily setup/update reverse mappings while creating/updating a mapping

* update readme screenshots + prefer 'Arm' terminology for enabling profile

* support more nullable types in mapping profile

* simplify groups

* add configurable grouping

* prevent wonky sorting across groups

* Add easy switch group option

* Fix being able to create corrupt profile

* fail loading ... (continued)

762 of 2383 branches covered (0.0%)

Branch coverage included in aggregate %.

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

3897 of 8183 relevant lines covered (47.62%)

12635.93 hits per line

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

0.0
/Key2Joy.Gui/Mapping/Triggers/Keyboard/KeyboardTriggerControl.cs
1
using System;
2
using System.Windows.Forms;
3
using Key2Joy.Contracts.Mapping;
4
using Key2Joy.Contracts.Mapping.Triggers;
5
using Key2Joy.LowLevelInput;
6
using Key2Joy.Mapping.Triggers;
7
using Key2Joy.Mapping.Triggers.Keyboard;
8

9
namespace Key2Joy.Gui.Mapping;
10

11
[MappingControl(
12
    ForType = typeof(KeyboardTrigger),
13
    ImageResourceName = "keyboard"
14
)]
15
public partial class KeyboardTriggerControl : UserControl, ITriggerOptionsControl
16
{
17
    private const string TEXT_CHANGE = "(press any key to select it as the trigger)";
18
    private const string TEXT_CHANGE_INSTRUCTION = "(click here, then press any key to set it as the trigger)";
19
    private readonly VirtualKeyConverter virtualKeyConverter = new();
×
20

21
    public event EventHandler OptionsChanged;
22

23
    private Keys keys;
24
    private bool isTrapping;
25

26
    public KeyboardTriggerControl()
×
27
    {
28
        this.InitializeComponent();
×
29

30
        // This captures global keyboard input and blocks default behaviour by setting e.Handled
31
        GlobalInputHook globalKeyboardHook = new();
×
32
        globalKeyboardHook.KeyboardInputEvent += this.OnKeyInputEvent;
×
33

34
        // Relieve input capturing by this mapping form
35
        Disposed += (s, e) =>
×
36
        {
×
37
            if (globalKeyboardHook == null)
×
38
            {
×
39
                return;
×
40
            }
×
41

×
42
            globalKeyboardHook.KeyboardInputEvent -= this.OnKeyInputEvent;
×
43
            globalKeyboardHook.Dispose();
×
44
            globalKeyboardHook = null;
×
45
        };
×
46
        ControlRemoved += (s, e) => this.Dispose();
×
47

48
        this.cmbPressState.DataSource = PressStates.ALL;
×
49
        this.cmbPressState.SelectedIndex = 0;
×
50

51
        // Removed because this is annoying when you want to just edit code
52
        //StartTrapping();
53
    }
×
54

55
    private void OnKeyInputEvent(object sender, GlobalKeyboardHookEventArgs e)
56
    {
57
        if (!this.isTrapping)
×
58
        {
59
            return;
×
60
        }
61

62
        this.keys = this.virtualKeyConverter.KeysFromVirtual(e.KeyboardData.VirtualCode);
×
63
        this.UpdateKeys();
×
64
        this.StopTrapping();
×
65
    }
×
66

67
    public void Select(AbstractTrigger trigger)
68
    {
69
        var thisTrigger = (KeyboardTrigger)trigger;
×
70

71
        this.keys = thisTrigger.Keys;
×
72
        this.cmbPressState.SelectedItem = thisTrigger.PressState;
×
73
        this.UpdateKeys();
×
74
    }
×
75

76
    public void Setup(AbstractTrigger trigger)
77
    {
78
        var thisTrigger = (KeyboardTrigger)trigger;
×
79

80
        thisTrigger.Keys = this.keys;
×
81
        thisTrigger.PressState = (PressState)this.cmbPressState.SelectedItem;
×
82
    }
×
83

84
    public bool CanMappingSave(AbstractTrigger trigger)
85
    {
86
        var thisTrigger = (KeyboardTrigger)trigger;
×
87

88
        if (thisTrigger.Keys != Keys.None)
×
89
        {
90
            return true;
×
91
        }
92

93
        MessageBox.Show(
×
94
            $"The trigger is not set to any key.",
×
95
            "Cannot save!",
×
96
            MessageBoxButtons.OK,
×
97
            MessageBoxIcon.Error
×
98
        );
×
99

100
        return false;
×
101
    }
102

103
    private void StartTrapping()
104
    {
105
        this.txtKeyBind.Text = TEXT_CHANGE;
×
106
        this.txtKeyBind.Focus();
×
107
        this.isTrapping = true;
×
108
    }
×
109

110
    private void StopTrapping() => this.isTrapping = false;
×
111

112
    private void UpdateKeys()
113
    {
114
        this.txtKeyBind.Text = $"{this.keys} {TEXT_CHANGE_INSTRUCTION}";
×
115
        OptionsChanged?.Invoke(this, EventArgs.Empty);
×
116
    }
×
117

118
    private void CmbPressedState_SelectedIndexChanged(object sender, EventArgs e) => OptionsChanged?.Invoke(this, EventArgs.Empty);
×
119

120
    private void TxtKeyBind_MouseUp(object sender, MouseEventArgs e) => this.StartTrapping();
×
121
}
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