aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.RemoteDesktop
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-03-04 21:32:42 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-03-04 21:32:42 +0200
commitf17d39f37cac50861467e07a7bee40534d20100a (patch)
tree1d6ba97191b866eee6ffc6ef904fe3803a84decd /Software/Visual_Studio/Tango.RemoteDesktop
parent565e48de649d3d14e6b82012b6aa2e3819a3c82c (diff)
downloadTango-f17d39f37cac50861467e07a7bee40534d20100a.tar.gz
Tango-f17d39f37cac50861467e07a7bee40534d20100a.zip
Improved "Notify Continuous Requests About Disconnection".
Integrated FSE/PPC Remote Desktop. Implemented RemoteDesktopService / RemoteDesktopProvider. Implemented Mouse/Keyboard gestures.
Diffstat (limited to 'Software/Visual_Studio/Tango.RemoteDesktop')
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Input/KeyboardController.cs79
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Input/MouseController.cs80
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardEventType.cs14
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardStateRequest.cs18
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardStateResponse.cs12
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseEventType.cs16
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseStateRequest.cs17
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseStateResponse.cs12
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Network/StopRemoteDesktopSessionRequest.cs12
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Network/StopRemoteDesktopSessionResponse.cs12
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/ScreenCaptureEngine.cs6
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/Tango.RemoteDesktop.csproj13
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/packages.config1
13 files changed, 291 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Input/KeyboardController.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Input/KeyboardController.cs
new file mode 100644
index 000000000..832018dac
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Input/KeyboardController.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+using WindowsInput;
+using WindowsInput.Native;
+
+namespace Tango.RemoteDesktop.Input
+{
+ public static class KeyboardController
+ {
+ private static InputSimulator simulator;
+
+ static KeyboardController()
+ {
+ simulator = new InputSimulator();
+ }
+
+ public static void KeyDown(Key key, bool ctrlDown, bool shitDown, bool altDown)
+ {
+ VirtualKeyCode virtualKey = (VirtualKeyCode)KeyInterop.VirtualKeyFromKey(key);
+
+ if (ctrlDown || shitDown || altDown)
+ {
+ List<VirtualKeyCode> modifierKeys = new List<VirtualKeyCode>();
+
+ if (ctrlDown)
+ {
+ modifierKeys.Add(VirtualKeyCode.LCONTROL);
+ }
+ if (shitDown)
+ {
+ modifierKeys.Add(VirtualKeyCode.LSHIFT);
+ }
+ if (altDown)
+ {
+ modifierKeys.Add(VirtualKeyCode.MENU);
+ }
+
+ simulator.Keyboard.ModifiedKeyStroke(modifierKeys, virtualKey);
+ }
+ else
+ {
+ simulator.Keyboard.KeyDown(virtualKey);
+ }
+ }
+
+ public static void KeyUp(Key key, bool ctrlDown, bool shitDown, bool altDown)
+ {
+ VirtualKeyCode virtualKey = (VirtualKeyCode)KeyInterop.VirtualKeyFromKey(key);
+
+ if (ctrlDown || shitDown || altDown)
+ {
+ List<VirtualKeyCode> modifierKeys = new List<VirtualKeyCode>();
+
+ if (ctrlDown)
+ {
+ modifierKeys.Add(VirtualKeyCode.LCONTROL);
+ }
+ if (shitDown)
+ {
+ modifierKeys.Add(VirtualKeyCode.LSHIFT);
+ }
+ if (altDown)
+ {
+ modifierKeys.Add(VirtualKeyCode.MENU);
+ }
+
+ simulator.Keyboard.ModifiedKeyStroke(modifierKeys, virtualKey);
+ }
+ else
+ {
+ simulator.Keyboard.KeyUp(virtualKey);
+ }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Input/MouseController.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Input/MouseController.cs
new file mode 100644
index 000000000..ec556f88c
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Input/MouseController.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.RemoteDesktop.Input
+{
+ public static class MouseController
+ {
+ [Flags]
+ public enum MouseEventFlags
+ {
+ LeftDown = 0x00000002,
+ LeftUp = 0x00000004,
+ MiddleDown = 0x00000020,
+ MiddleUp = 0x00000040,
+ Move = 0x00000001,
+ Absolute = 0x00008000,
+ RightDown = 0x00000008,
+ RightUp = 0x00000010
+ }
+
+ [DllImport("user32.dll", EntryPoint = "SetCursorPos")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static extern bool SetCursorPos(int x, int y);
+
+ [DllImport("user32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static extern bool GetCursorPos(out MousePoint lpMousePoint);
+
+ [DllImport("user32.dll")]
+ private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
+
+ public static void SetCursorPosition(int x, int y)
+ {
+ SetCursorPos(x, y);
+ }
+
+ public static void SetCursorPosition(MousePoint point)
+ {
+ SetCursorPos(point.X, point.Y);
+ }
+
+ public static MousePoint GetCursorPosition()
+ {
+ MousePoint currentMousePoint;
+ var gotPoint = GetCursorPos(out currentMousePoint);
+ if (!gotPoint) { currentMousePoint = new MousePoint(0, 0); }
+ return currentMousePoint;
+ }
+
+ public static void MouseEvent(MouseEventFlags value)
+ {
+ MousePoint position = GetCursorPosition();
+
+ mouse_event
+ ((int)value,
+ position.X,
+ position.Y,
+ 0,
+ 0)
+ ;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct MousePoint
+ {
+ public int X;
+ public int Y;
+
+ public MousePoint(int x, int y)
+ {
+ X = x;
+ Y = y;
+ }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardEventType.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardEventType.cs
new file mode 100644
index 000000000..b1b5b0353
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardEventType.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.RemoteDesktop.Network
+{
+ public enum KeyboardEventType
+ {
+ Up,
+ Down
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardStateRequest.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardStateRequest.cs
new file mode 100644
index 000000000..27ae49f64
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardStateRequest.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+
+namespace Tango.RemoteDesktop.Network
+{
+ public class KeyboardStateRequest
+ {
+ public KeyboardEventType EventType { get; set; }
+ public Key Key { get; set; }
+ public bool IsCtrlDown { get; set; }
+ public bool IsShiftDown { get; set; }
+ public bool IsAltDown { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardStateResponse.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardStateResponse.cs
new file mode 100644
index 000000000..6544078f0
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Network/KeyboardStateResponse.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.RemoteDesktop.Network
+{
+ public class KeyboardStateResponse
+ {
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseEventType.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseEventType.cs
new file mode 100644
index 000000000..2c9f84e03
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseEventType.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.RemoteDesktop.Network
+{
+ public enum MouseEventType
+ {
+ Down,
+ Up,
+ Move,
+ DoubleClick
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseStateRequest.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseStateRequest.cs
new file mode 100644
index 000000000..36e98351f
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseStateRequest.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Input;
+
+namespace Tango.RemoteDesktop.Network
+{
+ public class MouseStateRequest
+ {
+ public MouseButton Button { get; set; }
+ public MouseEventType EventType { get; set; }
+ public Point Location { get; set; }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseStateResponse.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseStateResponse.cs
new file mode 100644
index 000000000..f67715d99
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Network/MouseStateResponse.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.RemoteDesktop.Network
+{
+ public class MouseStateResponse
+ {
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Network/StopRemoteDesktopSessionRequest.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Network/StopRemoteDesktopSessionRequest.cs
new file mode 100644
index 000000000..058f5bbe1
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Network/StopRemoteDesktopSessionRequest.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.RemoteDesktop.Network
+{
+ public class StopRemoteDesktopSessionRequest
+ {
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Network/StopRemoteDesktopSessionResponse.cs b/Software/Visual_Studio/Tango.RemoteDesktop/Network/StopRemoteDesktopSessionResponse.cs
new file mode 100644
index 000000000..92a239d11
--- /dev/null
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Network/StopRemoteDesktopSessionResponse.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.RemoteDesktop.Network
+{
+ public class StopRemoteDesktopSessionResponse
+ {
+ }
+}
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/ScreenCaptureEngine.cs b/Software/Visual_Studio/Tango.RemoteDesktop/ScreenCaptureEngine.cs
index 81efb6a30..8920b983b 100644
--- a/Software/Visual_Studio/Tango.RemoteDesktop/ScreenCaptureEngine.cs
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/ScreenCaptureEngine.cs
@@ -111,7 +111,6 @@ namespace Tango.RemoteDesktop
if (IsStarted)
{
IsStarted = false;
- _previousBitmap?.Dispose();
}
}
@@ -180,15 +179,20 @@ namespace Tango.RemoteDesktop
catch (Exception ex)
{
Debug.WriteLine($"Error in screen capture engine: {ex.Message}");
+ _previousBitmap = null;
}
int delay = Math.Max(5, (1000 / FrameRate) - (int)watch.ElapsedMilliseconds);
Thread.Sleep(delay);
}
+
+ _previousBitmap = null;
}
private void OnFrameReceived(Bitmap currentBitmap, TFrame diffFrame, uint differenceCount)
{
+ if (!IsStarted) return;
+
FrameReceived?.Invoke(this, new ScreenCaptureFrameReceivedEventArgs<TFrame>()
{
Frame = new ScreenCaptureFrame<TFrame>(currentBitmap, diffFrame)
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/Tango.RemoteDesktop.csproj b/Software/Visual_Studio/Tango.RemoteDesktop/Tango.RemoteDesktop.csproj
index b0feb438d..dfffe90ec 100644
--- a/Software/Visual_Studio/Tango.RemoteDesktop/Tango.RemoteDesktop.csproj
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/Tango.RemoteDesktop.csproj
@@ -66,6 +66,9 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
+ <Reference Include="WindowsInput, Version=1.0.4.0, Culture=neutral, PublicKeyToken=9b287f7dc5073cad, processorArchitecture=MSIL">
+ <HintPath>..\packages\InputSimulator.1.0.4.0\lib\net20\WindowsInput.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BitmapComparerResult.cs" />
@@ -82,11 +85,21 @@
<Compile Include="Engines\RasterScreenCaptureEngine.cs" />
<Compile Include="Engines\VectorScreenCaptureEngine.cs" />
<Compile Include="Frames\VectorFrameColor.cs" />
+ <Compile Include="Input\KeyboardController.cs" />
+ <Compile Include="Input\MouseController.cs" />
<Compile Include="IScreenCaptureEngine.cs" />
<Compile Include="MaxDifferencesReachedException.cs" />
+ <Compile Include="Network\KeyboardEventType.cs" />
+ <Compile Include="Network\KeyboardStateRequest.cs" />
+ <Compile Include="Network\KeyboardStateResponse.cs" />
+ <Compile Include="Network\MouseEventType.cs" />
+ <Compile Include="Network\MouseStateRequest.cs" />
+ <Compile Include="Network\MouseStateResponse.cs" />
<Compile Include="Network\RemoteDesktopPacket.cs" />
<Compile Include="Network\StartRemoteDesktopSessionRequest.cs" />
<Compile Include="Network\StartRemoteDesktopSessionResponse.cs" />
+ <Compile Include="Network\StopRemoteDesktopSessionRequest.cs" />
+ <Compile Include="Network\StopRemoteDesktopSessionResponse.cs" />
<Compile Include="Quantization\ColorBgra.cs" />
<Compile Include="Quantization\OctreeQuantizer.cs" />
<Compile Include="Quantization\PaletteTable.cs" />
diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/packages.config b/Software/Visual_Studio/Tango.RemoteDesktop/packages.config
index 2cbb3038a..67634c01e 100644
--- a/Software/Visual_Studio/Tango.RemoteDesktop/packages.config
+++ b/Software/Visual_Studio/Tango.RemoteDesktop/packages.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="InputSimulator" version="1.0.4.0" targetFramework="net461" />
<package id="Quamotion.TurboJpegWrapper" version="1.5.69" targetFramework="net461" />
</packages> \ No newline at end of file