Skip to content

Commit b0f408b

Browse files
Merge pull request #119 from nullinside-development-group/feat/skip
Feat/skip
2 parents db7eddd + fb4c6c2 commit b0f408b

21 files changed

+1530
-52
lines changed

src/TwitchStreamingTools/Configuration.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
using Nullinside.Api.Common.Twitch;
1111

12+
using TwitchStreamingTools.Controls.ViewModels;
1213
using TwitchStreamingTools.Models;
1314
using TwitchStreamingTools.Utilities;
1415

@@ -85,6 +86,9 @@ public static Configuration Instance {
8586
/// <inheritdoc />
8687
public bool SayUsernameWithMessage { get; set; }
8788

89+
/// <inheritdoc />
90+
public Keybind? SkipTtsKey { get; set; } = new() { Key = Keys.End };
91+
8892
/// <summary>
8993
/// Writes the configuration file to disk.
9094
/// </summary>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:viewModels="clr-namespace:TwitchStreamingTools.Controls.ViewModels"
6+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
7+
x:Class="TwitchStreamingTools.Controls.Keybind"
8+
x:DataType="viewModels:KeybindViewModel">
9+
<StackPanel>
10+
<Button Content="{Binding Keybind}" Command="{Binding ListenForKeystroke}" />
11+
</StackPanel>
12+
</UserControl>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Avalonia.Controls;
2+
3+
namespace TwitchStreamingTools.Controls;
4+
5+
/// <summary>
6+
/// Represents a keybind.
7+
/// </summary>
8+
public partial class Keybind : UserControl {
9+
/// <summary>
10+
/// Initializes a new instance of the <see cref="Keybind" /> class.
11+
/// </summary>
12+
public Keybind() {
13+
InitializeComponent();
14+
}
15+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Text;
2+
3+
using TwitchStreamingTools.Models;
4+
5+
namespace TwitchStreamingTools.Controls.ViewModels;
6+
7+
/// <summary>
8+
/// A keybind.
9+
/// </summary>
10+
public class Keybind {
11+
/// <summary>
12+
/// The key pressed.
13+
/// </summary>
14+
public Keys Key { get; set; }
15+
16+
/// <summary>
17+
/// Indicates whether the Control (Ctrl) key is pressed as part of the keybind.
18+
/// </summary>
19+
public bool IsCtrl { get; set; }
20+
21+
/// <summary>
22+
/// Indicates whether the Shift key is pressed as part of the keybind.
23+
/// </summary>
24+
public bool IsShift { get; set; }
25+
26+
/// <summary>
27+
/// Indicates whether the Alt key is pressed as part of the keybind.
28+
/// </summary>
29+
public bool IsAlt { get; set; }
30+
31+
/// <summary>
32+
/// Returns a string representation of the keybind, including any modifier keys (Ctrl, Shift, Alt) and the key itself.
33+
/// </summary>
34+
/// <returns>
35+
/// A string representing the current keybind in the format of "Ctrl + Shift + Alt + Key",
36+
/// including only the applicable modifiers.
37+
/// </returns>
38+
public override string ToString() {
39+
var sb = new StringBuilder();
40+
if (IsCtrl) {
41+
sb.Append("Ctrl + ");
42+
}
43+
44+
if (IsShift) {
45+
sb.Append("Shift + ");
46+
}
47+
48+
if (IsAlt) {
49+
sb.Append("Alt + ");
50+
}
51+
52+
sb.Append(Key);
53+
return sb.ToString();
54+
}
55+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System.Reactive;
2+
3+
using ReactiveUI;
4+
5+
using TwitchStreamingTools.Services;
6+
using TwitchStreamingTools.ViewModels;
7+
8+
namespace TwitchStreamingTools.Controls.ViewModels;
9+
10+
/// <summary>
11+
/// Handles storing information required to visualize a keybind.
12+
/// </summary>
13+
public class KeybindViewModel : ViewModelBase {
14+
/// <summary>
15+
/// The listener for keystrokes on the keyboard.
16+
/// </summary>
17+
private readonly IGlobalKeyPressService _service;
18+
19+
/// <summary>
20+
/// The keybind, if set.
21+
/// </summary>
22+
private Keybind? _keybind;
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="KeybindViewModel" /> class.
26+
/// </summary>
27+
/// <param name="service">The listener for keystrokes on the keyboard.</param>
28+
public KeybindViewModel(IGlobalKeyPressService service) {
29+
_service = service;
30+
ListenForKeystroke = ReactiveCommand.Create(StartListenKeystroke);
31+
}
32+
33+
/// <summary>
34+
/// The keybind.
35+
/// </summary>
36+
public Keybind? Keybind {
37+
get => _keybind;
38+
set => this.RaiseAndSetIfChanged(ref _keybind, value);
39+
}
40+
41+
/// <summary>
42+
/// Listens for keystrokes.
43+
/// </summary>
44+
public ReactiveCommand<Unit, Unit> ListenForKeystroke { get; }
45+
46+
/// <summary>
47+
/// Starts listening for keystrokes.
48+
/// </summary>
49+
private void StartListenKeystroke() {
50+
_service.OnKeystroke -= OnKeystroke;
51+
_service.OnKeystroke += OnKeystroke;
52+
}
53+
54+
/// <summary>
55+
/// Called whenever a keystroke is pressed.
56+
/// </summary>
57+
/// <param name="keybind">The key that was press.</param>
58+
private void OnKeystroke(Keybind keybind) {
59+
if (_service.IsModifier(keybind.Key)) {
60+
return;
61+
}
62+
63+
Keybind = keybind;
64+
_service.OnKeystroke -= OnKeystroke;
65+
}
66+
}

src/TwitchStreamingTools/IConfiguration.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
using Nullinside.Api.Common.Twitch;
44

5+
using TwitchStreamingTools.Controls.ViewModels;
56
using TwitchStreamingTools.Models;
67

78
namespace TwitchStreamingTools;
@@ -50,6 +51,11 @@ public interface IConfiguration {
5051
/// </summary>
5152
bool SayUsernameWithMessage { get; set; }
5253

54+
/// <summary>
55+
/// The key press to skip the TTS.
56+
/// </summary>
57+
Keybind? SkipTtsKey { get; set; }
58+
5359
/// <summary>
5460
/// Writes the configuration file to disk.
5561
/// </summary>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace TwitchStreamingTools.Models;
5+
6+
/// <summary>
7+
/// The structure representing the key pressed.
8+
/// </summary>
9+
[StructLayout(LayoutKind.Sequential)]
10+
internal struct KeyboardLowLevelHookStruct {
11+
/// <summary>
12+
/// The keystroke.
13+
/// </summary>
14+
public int vkCode;
15+
16+
/// <summary>
17+
/// The scan code.
18+
/// </summary>
19+
public int scanCode;
20+
21+
/// <summary>
22+
/// The flags.
23+
/// </summary>
24+
public int flags;
25+
26+
/// <summary>
27+
/// The time the key was pressed.
28+
/// </summary>
29+
public int time;
30+
31+
/// <summary>
32+
/// The extra info.
33+
/// </summary>
34+
public IntPtr dwExtraInfo;
35+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace TwitchStreamingTools.Models;
2+
3+
/// <summary>
4+
/// Information on what kind of event it is.
5+
/// </summary>
6+
public enum KeyboardMessage {
7+
/// <summary>
8+
/// The key was pressed down.
9+
/// </summary>
10+
KEY_DOWN = 0x100,
11+
12+
/// <summary>
13+
/// The key was released after being pressed down.
14+
/// </summary>
15+
KEY_UP = 0x101,
16+
17+
/// <summary>
18+
/// No idea.
19+
/// </summary>
20+
SYS_KEY_DOWN = 0x104,
21+
22+
/// <summary>
23+
/// Don't ask me.
24+
/// </summary>
25+
SYS_KEY_UP = 0x105
26+
}

0 commit comments

Comments
 (0)