Skip to content

Commit a19f81d

Browse files
committed
Long-Press for the toggle button
1 parent 06f3378 commit a19f81d

File tree

6 files changed

+85
-5
lines changed

6 files changed

+85
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ The toggle button activates the vjoy button when pressed. The vjoy button stays
4646
If there is a simple button controlling the same vjoy button it will also update the state when the simple button is pressed.
4747
In MultiActions the state is toggled as usual.
4848

49+
The toggle button now also supports long-press now to trigger a different button id. :new:
50+
4951
#### Axis
5052

5153
The Axis action can be used in the Steam Deck as buttons or in the Steam Deck+ as a dial.

streamdeck-vjoy-w4rl0ck/Actions/ToggleButtonAction.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Newtonsoft.Json;
55
using Newtonsoft.Json.Linq;
66
using streamdeck_vjoy_w4rl0ck.Utils;
7+
using Timer = System.Timers.Timer;
78

89
namespace streamdeck_vjoy_w4rl0ck.Actions;
910

@@ -18,6 +19,11 @@ public ToggleButtonAction(SDConnection connection, InitialPayload payload) : bas
1819
SimpleVJoyInterface.UpdateButtonSignal += SimpleVJoyInterface_OnUpdateButtonSignal;
1920
SimpleVJoyInterface.VJoyStatusUpdateSignal += SimpleVJoyInterface_OnVJoyStatusUpdate;
2021

22+
_longPressTimer.AutoReset = false;
23+
_longPressTimer.Elapsed += (sender, e) => LongPressTimerTick();
24+
_buttonTimer.AutoReset = false;
25+
_buttonTimer.Elapsed += (sender, e) => ButtonTimerTick();
26+
2127
if (payload.Settings == null || payload.Settings.Count == 0)
2228
{
2329
_settings = PluginSettings.CreateDefaultSettings();
@@ -48,14 +54,34 @@ private void SimpleVJoyInterface_OnUpdateButtonSignal(uint buttonId, bool state)
4854

4955
public override void KeyPressed(KeyPayload payload)
5056
{
51-
SimpleVJoyInterface.Instance.ButtonState(_settings.ButtonId, SimpleVJoyInterface.ButtonAction.Toggle);
57+
if (_settings.LongPressButtonId != null && _settings.LongPressButtonId > 0) _longPressTimer.Start();
5258
}
5359

5460
public override void KeyReleased(KeyPayload payload)
5561
{
62+
if (!_longPressTimer.Enabled) return;
63+
_longPressTimer.Stop();
64+
SimpleVJoyInterface.Instance.ButtonState(_settings.ButtonId, SimpleVJoyInterface.ButtonAction.Toggle);
5665
Connection.SetStateAsync(_buttonState ? 1u : 0u);
5766
}
5867

68+
private void LongPressTimerTick()
69+
{
70+
if (_settings.LongPressButtonId == null) return;
71+
SimpleVJoyInterface.Instance.ButtonState((uint)_settings.LongPressButtonId,
72+
SimpleVJoyInterface.ButtonAction.Down);
73+
_buttonTimer.Start();
74+
Connection.ShowOk();
75+
}
76+
77+
private void ButtonTimerTick()
78+
{
79+
if (_settings.LongPressButtonId != null)
80+
SimpleVJoyInterface.Instance.ButtonState((uint)_settings.LongPressButtonId,
81+
SimpleVJoyInterface.ButtonAction.Up);
82+
}
83+
84+
5985
public override void OnTick()
6086
{
6187
}
@@ -103,11 +129,15 @@ private class PluginSettings
103129
[JsonProperty(PropertyName = "buttonId")]
104130
public uint ButtonId { get; set; }
105131

132+
[JsonProperty(PropertyName = "lpButtonId")]
133+
public uint? LongPressButtonId { get; set; }
134+
106135
public static PluginSettings CreateDefaultSettings()
107136
{
108137
var instance = new PluginSettings
109138
{
110-
ButtonId = 1
139+
ButtonId = 1,
140+
LongPressButtonId = 0
111141
};
112142
return instance;
113143
}
@@ -144,6 +174,8 @@ private async Task SendPropertyInspectorData()
144174
#region Private Members
145175

146176
private readonly PluginSettings _settings;
177+
private readonly Timer _buttonTimer = new(100);
178+
private readonly Timer _longPressTimer = new(600);
147179
private bool _buttonState;
148180
private bool _propertyInspectorIsOpen;
149181

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<meta content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,minimal-ui,viewport-fit=cover"
6+
name=viewport>
7+
<meta content=yes name=apple-mobile-web-app-capable>
8+
<meta content=black name=apple-mobile-web-app-status-bar-style>
9+
<title>vJoy Settings</title>
10+
<link href="sdpi.css" rel="stylesheet">
11+
<script src="sdtools.common.js"></script>
12+
<script src="local.js"></script>
13+
</head>
14+
<body>
15+
<div class="sdpi-wrapper">
16+
17+
<div class="sdpi-heading">vJoy Settings</div>
18+
<div class="sdpi-item">
19+
<div class="sdpi-item-label">Toggle Button ID</div>
20+
<input class="sdpi-item-value" data-default="1" data-setting="buttonId" pattern="\d{1,3}" placeholder="1-128"
21+
required>
22+
</div>
23+
24+
<div class="sdpi-item">
25+
<div class="sdpi-item-label">Long Press ID</div>
26+
<input class="sdpi-item-value" data-default="" data-setting="lpButtonId" pattern="\d{0,3}" placeholder="1-128">
27+
</div>
28+
29+
<div class=" sdpi-heading">Global Settings
30+
</div>
31+
<div class="sdpi-item">
32+
<details class="message info">
33+
<summary>Status: <span id="status"></span></summary>
34+
</details>
35+
</div>
36+
37+
<div class="sdpi-item">
38+
<button class="sdpi-item-value" data-open="Global.html">Open Configuration</button>
39+
</div>
40+
41+
</div>
42+
</body>
43+
</html>

streamdeck-vjoy-w4rl0ck/PropertyInspector/TriggerButtonAction.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<div class="sdpi-item">
2626
<div class="sdpi-item-label">Button ID 2</div>
27-
<input class="sdpi-item-value" data-default="2" data-setting="buttonId1" pattern="\d{1,3}" placeholder="1-128"
27+
<input class="sdpi-item-value" data-default="2" data-setting="buttonId2" pattern="\d{1,3}" placeholder="1-128"
2828
required>
2929
</div>
3030

streamdeck-vjoy-w4rl0ck/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"DisableAutomaticStates": true,
7171
"SupportedInMultiActions": true,
7272
"Tooltip": "A button that can toggle a vJoy button",
73-
"PropertyInspectorPath": "PropertyInspector/SimpleButtonAction.html"
73+
"PropertyInspectorPath": "PropertyInspector/ToggleButtonAction.html"
7474
},
7575
{
7676
"UUID": "dev.w4rl0ck.streamdeck.vjoy.axiskeydialaction",
@@ -129,7 +129,7 @@
129129
"Description": "The StreamDeck vJoy Controller Plugin is a powerful tool that transforms your StreamDeck into a flexible vJoy controller. This plugin allows users to map StreamDeck buttons to vJoy virtual joystick inputs, enhancing the interactivity and control within any software that supports joystick inputs.",
130130
"Icon": "Images/joystick-svgrepo-com",
131131
"URL": "https://github.com/bastianh/streamdeck-vjoy-w4rl0ck",
132-
"Version": "0.2.2",
132+
"Version": "0.2.3",
133133
"CodePath": "streamdeck-vjoy-w4rl0ck",
134134
"Category": "vJoy",
135135
"CategoryIcon": "Images/joystick-svgrepo-com",

streamdeck-vjoy-w4rl0ck/streamdeck-vjoy-w4rl0ck.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@
114114
<None Update="PropertyInspector\TriggerButtonAction.html">
115115
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
116116
</None>
117+
<None Update="PropertyInspector\ToggleButtonAction.html">
118+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
119+
</None>
117120
</ItemGroup>
118121

119122
<ItemGroup>

0 commit comments

Comments
 (0)