-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.cs
126 lines (110 loc) · 3.8 KB
/
Client.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Input;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsInput;
using InputTransmiter.Core;
using InputTransmiter.Language;
namespace InputTransmiter
{
public partial class Client : Form
{
NetworksUtilsClient client;
Lang lang;
bool terminated = false;
Dictionary<VirtualKeyCode, bool> pressed;
bool connect = false;
public Client()
{
InitializeComponent();
this.FormClosing += this_close;
this.FormBorderStyle = FormBorderStyle.FixedSingle;
lang = new Lang();
client = new NetworksUtilsClient();
Program.log.addLoggingElement(client.log);
Program.log.addLoggingElement(lang.log);
lang.LoadLang(Program.Language);
button1.Text = lang.strings["butCon"];
button2.Text = lang.strings["butFoc"];
button3.Text = lang.strings["butStop"];
button2.Enabled = button3.Enabled = false;
statusStrip1.Items[0].ForeColor = Color.Red;
statusStrip1.Items[0].Text = lang.strings["ncon"];
}
private void this_close(object sender, FormClosingEventArgs e)
{
if(client.client.TcpClient != null)
if (client.client.TcpClient.Connected)
client.client.Disconnect();
(new Main()).Show();
}
private void button1_Click(object sender, EventArgs e)
{
if (!client.connect(textBox1.Text, (int)numericUpDown1.Value)){
MessageBox.Show(lang.strings["conMsg"]);
return;
}
statusStrip1.Items[0].ForeColor = Color.Green;
statusStrip1.Items[0].Text = lang.strings["con"];
connect = true;
button2.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
pressed = new Dictionary<VirtualKeyCode, bool>();
foreach(VirtualKeyCode key in Enum.GetValues(typeof(VirtualKeyCode)))
{
pressed[key] = false;
}
this.Focus();
Program.log.log("Pressed");
terminated = false;
this.KeyDown += this_keyDown;
this.KeyUp += this_keyUp;
this.ResumeLayout(false);
this.KeyPreview = true;
button3.Enabled = true;
button2.Enabled = false;
groupBox1.Enabled = false;
}
private void this_keyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
VirtualKeyCode key = (VirtualKeyCode)e.KeyValue;
Program.log.log("Key press down : " + key.ToString());
e.Handled = true;
pressed[key] = false;
client.sendKey(key, true);
}
private void this_keyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
VirtualKeyCode key = (VirtualKeyCode)e.KeyValue;
if (!pressed[key])
{
Program.log.log("Pressed : " + key.ToString());
client.sendKey(key, false);
pressed[key] = true;
}
}
private void button3_Click(object sender, EventArgs e)
{
if (connect)
button2.Enabled = true;
else
button2.Enabled = false;
button3.Enabled = false;
groupBox1.Enabled = true;
this.KeyDown -= this_keyDown;
this.KeyUp -= this_keyUp;
}
private void Client_Load(object sender, EventArgs e)
{
}
}
}