-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
100 lines (87 loc) · 2.95 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
100 lines (87 loc) · 2.95 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace Paster
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Title += System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
timer.Tick += Timer_Tick;
}
private void Timer_Tick(object sender, EventArgs e)
{
//Console.WriteLine("tick");
int n = (int)timer.Tag;
if (n > 0)
{
timer.Tag = n - 1;
Dispatcher.Invoke(() =>
{
BtnStart.Content = $"{n}s left";
BtnStart.IsEnabled = false;
});
}
else
{
var s = TbInput.Text;
s = s.Replace(Environment.NewLine, "\n");
//Console.WriteLine(s);
string[] listSpecialkey = { "+", "^", "%", "~","(",")" };// https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys?redirectedfrom=MSDN&view=net-5.0
s = s.Replace("{", "亓");
s = s.Replace("}", "捸");
s = s.Replace("亓", "{{}");
s = s.Replace("捸", "{}}");
foreach (var key in listSpecialkey)
{
s = s.Replace(key, "{" + key + "}");
}
Console.WriteLine(s);
SendKeys.SendWait(s);
Dispatcher.Invoke(() =>
{
BtnStart.Content = "点击后3s开始";
BtnStart.IsEnabled = true;
});
timer.IsEnabled = false;
}
}
private readonly DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) };
private void BtnStart_Click(object sender, RoutedEventArgs e)
{
int seconds = 3;
timer.Tag = seconds;
timer.Start();
}
private void HlProject_Click(object sender, RoutedEventArgs e)
{
Hyperlink link = sender as Hyperlink;
Process.Start(new ProcessStartInfo(link.NavigateUri.AbsoluteUri));
}
private void HlAuthor_Click(object sender, RoutedEventArgs e)
{
Hyperlink link = sender as Hyperlink;
Process.Start(new ProcessStartInfo(link.NavigateUri.AbsoluteUri));
}
}
}