Skip to content

Commit 60871b4

Browse files
committed
Commit staged
1 parent c91dd46 commit 60871b4

22 files changed

+1516
-0
lines changed

App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
5+
</startup>
6+
</configuration>

Client.Designer.cs

Lines changed: 153 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Client.cs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Windows.Input;
10+
using System.Threading.Tasks;
11+
using System.Windows.Forms;
12+
using System.Windows.Input;
13+
using WindowsInput;
14+
using Albin.Commons.Logging;
15+
using InputTransmiter.Core;
16+
using InputTransmiter.Language;
17+
18+
namespace InputTransmiter
19+
{
20+
public partial class Client : Form
21+
{
22+
NetworksUtilsClient client;
23+
Lang lang;
24+
bool terminated = false;
25+
Dictionary<VirtualKeyCode, bool> pressed;
26+
bool connect = false;
27+
public Client()
28+
{
29+
InitializeComponent();
30+
31+
this.FormClosing += this_close;
32+
33+
lang = new Lang();
34+
client = new NetworksUtilsClient();
35+
Program.log.addLoggingElement(client.log);
36+
Program.log.addLoggingElement(lang.log);
37+
38+
lang.LoadLang(Program.Language);
39+
button1.Text = lang.strings["butCon"];
40+
button2.Text = lang.strings["butFoc"];
41+
button3.Text = lang.strings["butStop"];
42+
43+
button2.Enabled = button3.Enabled = false;
44+
45+
}
46+
47+
private void this_close(object sender, FormClosingEventArgs e)
48+
{
49+
if(client.client.TcpClient != null)
50+
if (client.client.TcpClient.Connected)
51+
client.client.Disconnect();
52+
(new Main()).Show();
53+
}
54+
55+
private void button1_Click(object sender, EventArgs e)
56+
{
57+
if (!client.connect(textBox1.Text, (int)numericUpDown1.Value)){
58+
MessageBox.Show("Erreur de connexion ...");
59+
return;
60+
61+
62+
}
63+
connect = true;
64+
button2.Enabled = true;
65+
}
66+
67+
private void button2_Click(object sender, EventArgs e)
68+
{
69+
pressed = new Dictionary<VirtualKeyCode, bool>();
70+
foreach(VirtualKeyCode key in Enum.GetValues(typeof(VirtualKeyCode)))
71+
{
72+
pressed[key] = false;
73+
}
74+
this.Focus();
75+
Program.log.log("Pressed");
76+
terminated = false;
77+
this.KeyDown += this_keyDown;
78+
this.KeyUp += this_keyUp;
79+
this.ResumeLayout(false);
80+
this.KeyPreview = true;
81+
82+
button3.Enabled = true;
83+
button2.Enabled = false;
84+
groupBox1.Enabled = false;
85+
}
86+
87+
private void this_keyUp(object sender, System.Windows.Forms.KeyEventArgs e)
88+
{
89+
VirtualKeyCode key = (VirtualKeyCode)e.KeyValue;
90+
Program.log.log("Key press down : " + key.ToString());
91+
e.Handled = true;
92+
pressed[key] = false;
93+
client.sendKey(key, true);
94+
}
95+
96+
private void this_keyDown(object sender, System.Windows.Forms.KeyEventArgs e)
97+
{
98+
VirtualKeyCode key = (VirtualKeyCode)e.KeyValue;
99+
if (!pressed[key])
100+
{
101+
Program.log.log("Pressed : " + key.ToString());
102+
client.sendKey(key, false);
103+
pressed[key] = true;
104+
}
105+
}
106+
107+
private void button3_Click(object sender, EventArgs e)
108+
{
109+
if (connect)
110+
button2.Enabled = true;
111+
else
112+
button2.Enabled = false;
113+
button3.Enabled = false;
114+
groupBox1.Enabled = true;
115+
this.KeyDown -= this_keyDown;
116+
this.KeyUp -= this_keyUp;
117+
}
118+
}
119+
}

0 commit comments

Comments
 (0)