-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
41 lines (33 loc) · 1.32 KB
/
MainWindow.xaml.cs
File metadata and controls
41 lines (33 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Input;
using NHotkey;
using NHotkey.Wpf;
namespace AutoClicker;
/// <summary>Interaction logic for MainWindow.xaml</summary>
public partial class MainWindow
{
private Timer? _timer;
public MainWindow()
{
HotkeyManager.Current.AddOrReplace("ToggleAutoClick", Key.F8, ModifierKeys.None, HotkeyAutoClicker);
InitializeComponent();
}
private void HotkeyAutoClicker(object? sender, HotkeyEventArgs e) =>
ToggleButtonAutoClick.IsChecked = ToggleButtonAutoClick.IsChecked != true;
private void ToggleButtonAutoClick_Checked(object sender, RoutedEventArgs e)
{
if (!int.TryParse(TextBoxInterval.Text, out int interval) || interval < 1)
{
TextBoxInterval.Text = "1";
interval = 1;
}
var period = TimeSpan.FromMilliseconds(interval);
_timer = new(_ => MouseOperations.Event(MouseOperations.EventFlag.Click), null, TimeSpan.Zero, period);
}
private void ToggleButtonAutoClick_UnChecked(object sender, RoutedEventArgs e) => _timer?.Dispose();
private void TextBoxInterval_OnPreviewTextInput(object sender, TextCompositionEventArgs e) =>
e.Handled = !Regex.IsMatch(e.Text, @"\d+");
}