forked from Bediveren/RemoteControllerCsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewerForm.cs
More file actions
131 lines (115 loc) · 4.2 KB
/
ViewerForm.cs
File metadata and controls
131 lines (115 loc) · 4.2 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
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
127
128
129
130
131
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using WindowsInput;
namespace RemoteControl
{
public partial class ViewerForm : Form
{
private const string CommandLeftMouseUP = "LFU";
private const string CommandLeftMouseDOWN = "LFD";
private const string CommandRightMouseUP = "RFU";
private const string CommandRightMouseDOWN = "RFD";
private const string CommandMiddleMouseUP = "MFU";
private const string CommandMiddleMouseDOWN = "MFD";
Form parentForm;
public ViewerForm(Form parentForm)
{
InitializeComponent();
this.parentForm = parentForm;
}
private void ViewerForm_Load(object sender, EventArgs e)
{
pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
ServerConnect.EventImageRecieved += ViewerForm_UpdatePicture;
ServerConnect.parentForm = this;
this.Capture = true;
new Task(() => ServerConnect.Listen()).Start();
}
private void ViewerForm_FormClosed(object sender, FormClosedEventArgs e)
{
parentForm.Show();
}
public void ViewerForm_UpdatePicture(object source, ServerEventArgs args)
{
pictureBox.Image = args.Image;
}
private void ViewerForm_Shown(object sender, EventArgs e)
{
}
private void ViewerForm_KeyDown(object sender, KeyEventArgs e)
{
if (ServerConnect.isOnline)
{
if (e.KeyCode == Keys.End)
{
ServerConnect.binaryWriter.Write(ServerConnect.CommandShutdown);
ServerConnect.binaryWriter.Flush();
}
else if(e.KeyCode == Keys.Pause)
{
if (ServerConnect.sendMouseInput == true) ServerConnect.sendMouseInput = false;
else ServerConnect.sendMouseInput = true;
}
else
{
ServerConnect.binaryWriter.Write(ServerConnect.CommandKeyPressed);
ServerConnect.binaryWriter.Write((Int32)e.KeyCode);
ServerConnect.binaryWriter.Flush();
}
}
}
private void CeaseConnection()
{
ServerConnect.isOnline = false;
ServerConnect.Disconnect(new ServerErrorHandler("Could not cease connection. Please terminate it manually"));
}
private void pictureBox_MouseUp(object sender, MouseEventArgs e)
{
if (ServerConnect.isOnline)
{
ServerConnect.binaryWriter.Write(ServerConnect.CommandMousePressed);
if (e.Button == MouseButtons.Left)
{
ServerConnect.binaryWriter.Write(CommandLeftMouseUP);
}
else if (e.Button == MouseButtons.Right)
{
ServerConnect.binaryWriter.Write(CommandRightMouseUP);
}
else
{
ServerConnect.binaryWriter.Write(CommandMiddleMouseUP);
}
ServerConnect.binaryWriter.Flush();
}
}
private void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
if (ServerConnect.isOnline)
{
ServerConnect.binaryWriter.Write(ServerConnect.CommandMousePressed);
if (e.Button == MouseButtons.Left)
{
ServerConnect.binaryWriter.Write(CommandLeftMouseDOWN);
}
else if (e.Button == MouseButtons.Right)
{
ServerConnect.binaryWriter.Write(CommandRightMouseDOWN);
}
else
{
ServerConnect.binaryWriter.Write(CommandMiddleMouseDOWN);
}
ServerConnect.binaryWriter.Flush();
}
}
}
}