-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
63 lines (49 loc) · 1.94 KB
/
Program.cs
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
using QwertyTranslator.Translator;
using WindowsKeyLogger;
using System;
using System.Windows.Forms;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Text;
namespace QwertyTranslator
{
public class Program
{
private static KeyLogger _qwertyTranslator;
[STAThread]
public static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
Start();
}
private static void Start()
{
var translator = new QwertyTranslatorMediator(new RusToEngQwertyTranslator(),
new EngToRusQwertyTranslator());
var updater = new ClipBoardUpdaterTextToText(translator);
_qwertyTranslator = new KeyLogger(Keys.LControlKey, Keys.N, updater.Update);
Application.ApplicationExit += Application_ApplicationExit;
_qwertyTranslator.Start();
Application.Run();
_qwertyTranslator.Stop();
}
private static void Application_ApplicationExit(object sender, EventArgs e) => _qwertyTranslator?.Stop();
private static void CurrentDomain_ProcessExit(object sender, EventArgs e) => _qwertyTranslator?.Stop();
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (!args.Name.StartsWith("KeyLogger"))
{
return null;
}
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("QwertyTranslator.KeyLogger.dll"))
{
var assemblyData = new byte[stream.Length];
stream.Read(assemblyData, 0, assemblyData.Length);
return Assembly.Load(assemblyData);
}
}
}
}