mirror of
https://github.com/immense/Remotely.git
synced 2025-10-26 11:27:15 +00:00
Add middle-mouse click.
This commit is contained in:
parent
140d0262aa
commit
4329266122
12
Desktop.Core/Enums/ButtonAction.cs
Normal file
12
Desktop.Core/Enums/ButtonAction.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Remotely.Desktop.Core.Enums
|
||||
{
|
||||
public enum ButtonAction
|
||||
{
|
||||
Down,
|
||||
Up
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,17 @@
|
||||
namespace Remotely.Desktop.Core.Interfaces
|
||||
using Remotely.Desktop.Core.Enums;
|
||||
using Remotely.Desktop.Core.Services;
|
||||
|
||||
namespace Remotely.Desktop.Core.Interfaces
|
||||
{
|
||||
public interface IKeyboardMouseInput
|
||||
{
|
||||
void SendKeyDown(string key);
|
||||
void SendKeyUp(string key);
|
||||
void SendMouseMove(double percentX, double percentY, Services.Viewer viewer);
|
||||
void SendLeftMouseDown(double percentX, double percentY, Services.Viewer viewer);
|
||||
void SendLeftMouseUp(double percentX, double percentY, Services.Viewer viewer);
|
||||
void SendRightMouseDown(double percentX, double percentY, Services.Viewer viewer);
|
||||
void SendRightMouseUp(double percentX, double percentY, Services.Viewer viewer);
|
||||
void SendMouseWheel(int deltaY);
|
||||
void SendText(string transferText);
|
||||
void ToggleBlockInput(bool toggleOn);
|
||||
void SetKeyStatesUp();
|
||||
void SendMouseButtonAction(int button, ButtonAction buttonAction, double percentX, double percentY, Viewer viewer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using MessagePack;
|
||||
using Remotely.Desktop.Core.Enums;
|
||||
using Remotely.Desktop.Core.Interfaces;
|
||||
using Remotely.Shared.Enums;
|
||||
using Remotely.Shared.Models.RemoteControlDtos;
|
||||
@ -197,14 +198,7 @@ namespace Remotely.Desktop.Core.Services
|
||||
private void MouseDown(byte[] message, Services.Viewer viewer)
|
||||
{
|
||||
var dto = MessagePackSerializer.Deserialize<MouseDownDto>(message);
|
||||
if (dto.Button == 0)
|
||||
{
|
||||
KeyboardMouseInput.SendLeftMouseDown(dto.PercentX, dto.PercentY, viewer);
|
||||
}
|
||||
else if (dto.Button == 2)
|
||||
{
|
||||
KeyboardMouseInput.SendRightMouseDown(dto.PercentX, dto.PercentY, viewer);
|
||||
}
|
||||
KeyboardMouseInput.SendMouseButtonAction(dto.Button, ButtonAction.Down, dto.PercentX, dto.PercentY, viewer);
|
||||
}
|
||||
|
||||
private void MouseMove(byte[] message, Services.Viewer viewer)
|
||||
@ -216,14 +210,7 @@ namespace Remotely.Desktop.Core.Services
|
||||
private void MouseUp(byte[] message, Services.Viewer viewer)
|
||||
{
|
||||
var dto = MessagePackSerializer.Deserialize<MouseUpDto>(message);
|
||||
if (dto.Button == 0)
|
||||
{
|
||||
KeyboardMouseInput.SendLeftMouseUp(dto.PercentX, dto.PercentY, viewer);
|
||||
}
|
||||
else if (dto.Button == 2)
|
||||
{
|
||||
KeyboardMouseInput.SendRightMouseUp(dto.PercentX, dto.PercentY, viewer);
|
||||
}
|
||||
KeyboardMouseInput.SendMouseButtonAction(dto.Button, ButtonAction.Up, dto.PercentX, dto.PercentY, viewer);
|
||||
}
|
||||
|
||||
private void MouseWheel(byte[] message)
|
||||
@ -262,8 +249,8 @@ namespace Remotely.Desktop.Core.Services
|
||||
private void Tap(byte[] message, Services.Viewer viewer)
|
||||
{
|
||||
var dto = MessagePackSerializer.Deserialize<TapDto>(message);
|
||||
KeyboardMouseInput.SendLeftMouseDown(dto.PercentX, dto.PercentY, viewer);
|
||||
KeyboardMouseInput.SendLeftMouseUp(dto.PercentX, dto.PercentY, viewer);
|
||||
KeyboardMouseInput.SendMouseButtonAction(0, ButtonAction.Down, dto.PercentX, dto.PercentY, viewer);
|
||||
KeyboardMouseInput.SendMouseButtonAction(0, ButtonAction.Up, dto.PercentX, dto.PercentY, viewer);
|
||||
}
|
||||
|
||||
private void ToggleAudio(byte[] message)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Remotely.Desktop.Core.Interfaces;
|
||||
using Remotely.Desktop.Core.Enums;
|
||||
using Remotely.Desktop.Core.Interfaces;
|
||||
using Remotely.Desktop.Core.Services;
|
||||
using Remotely.Desktop.Linux.X11Interop;
|
||||
using Remotely.Shared.Utilities;
|
||||
@ -57,35 +58,6 @@ namespace Remotely.Desktop.Linux.Services
|
||||
|
||||
}
|
||||
|
||||
public void SendLeftMouseDown(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
try
|
||||
{
|
||||
Init();
|
||||
SendMouseMove(percentX, percentY, viewer);
|
||||
LibXtst.XTestFakeButtonEvent(Display, 1, true, 0);
|
||||
LibX11.XSync(Display, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendLeftMouseUp(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
try
|
||||
{
|
||||
Init();
|
||||
SendMouseMove(percentX, percentY, viewer);
|
||||
LibXtst.XTestFakeButtonEvent(Display, 1, false, 0);
|
||||
LibX11.XSync(Display, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendMouseMove(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
@ -158,6 +130,25 @@ namespace Remotely.Desktop.Linux.Services
|
||||
}
|
||||
}
|
||||
|
||||
public void SendMouseButtonAction(int button, ButtonAction buttonAction, double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
try
|
||||
{
|
||||
var isPressed = buttonAction == ButtonAction.Down;
|
||||
// Browser buttons start at 0. XTest starts at 1.
|
||||
var mouseButton = (uint)(button + 1);
|
||||
|
||||
Init();
|
||||
SendMouseMove(percentX, percentY, viewer);
|
||||
LibXtst.XTestFakeButtonEvent(Display, mouseButton, isPressed, 0);
|
||||
LibX11.XSync(Display, false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Write(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendText(string transferText)
|
||||
{
|
||||
foreach (var key in transferText)
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Remotely.Desktop.Core.Interfaces;
|
||||
using Remotely.Desktop.Core.Enums;
|
||||
using Remotely.Desktop.Core.Interfaces;
|
||||
using Remotely.Desktop.Core.Services;
|
||||
using Remotely.Shared.Utilities;
|
||||
using Remotely.Shared.Win32;
|
||||
@ -77,29 +78,60 @@ namespace Remotely.Desktop.Win.Services
|
||||
});
|
||||
}
|
||||
|
||||
public void SendLeftMouseDown(double percentX, double percentY, Viewer viewer)
|
||||
public void SendMouseButtonAction(int button, ButtonAction buttonAction, double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
MOUSEEVENTF mouseEvent;
|
||||
switch (button)
|
||||
{
|
||||
case 0:
|
||||
switch (buttonAction)
|
||||
{
|
||||
case ButtonAction.Down:
|
||||
mouseEvent = MOUSEEVENTF.LEFTDOWN;
|
||||
break;
|
||||
case ButtonAction.Up:
|
||||
mouseEvent = MOUSEEVENTF.LEFTUP;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
switch (buttonAction)
|
||||
{
|
||||
case ButtonAction.Down:
|
||||
mouseEvent = MOUSEEVENTF.MIDDLEDOWN;
|
||||
break;
|
||||
case ButtonAction.Up:
|
||||
mouseEvent = MOUSEEVENTF.MIDDLEUP;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
switch (buttonAction)
|
||||
{
|
||||
case ButtonAction.Down:
|
||||
mouseEvent = MOUSEEVENTF.RIGHTDOWN;
|
||||
break;
|
||||
case ButtonAction.Up:
|
||||
mouseEvent = MOUSEEVENTF.RIGHTUP;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
var xyPercent = GetAbsolutePercentFromRelativePercent(percentX, percentY, viewer.Capturer);
|
||||
// Coordinates must be normalized. The bottom-right coordinate is mapped to 65535.
|
||||
var normalizedX = xyPercent.Item1 * 65535D;
|
||||
var normalizedY = xyPercent.Item2 * 65535D;
|
||||
var union = new InputUnion() { mi = new MOUSEINPUT() { dwFlags = MOUSEEVENTF.ABSOLUTE | MOUSEEVENTF.LEFTDOWN | MOUSEEVENTF.VIRTUALDESK, dx = (int)normalizedX, dy = (int)normalizedY, time = 0, mouseData = 0, dwExtraInfo = GetMessageExtraInfo() } };
|
||||
var input = new INPUT() { type = InputType.MOUSE, U = union };
|
||||
SendInput(1, new INPUT[] { input }, INPUT.Size);
|
||||
});
|
||||
}
|
||||
|
||||
public void SendLeftMouseUp(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
var xyPercent = GetAbsolutePercentFromRelativePercent(percentX, percentY, viewer.Capturer);
|
||||
// Coordinates must be normalized. The bottom-right coordinate is mapped to 65535.
|
||||
var normalizedX = xyPercent.Item1 * 65535D;
|
||||
var normalizedY = xyPercent.Item2 * 65535D;
|
||||
var union = new InputUnion() { mi = new MOUSEINPUT() { dwFlags = MOUSEEVENTF.ABSOLUTE | MOUSEEVENTF.LEFTUP | MOUSEEVENTF.VIRTUALDESK, dx = (int)normalizedX, dy = (int)normalizedY, time = 0, mouseData = 0, dwExtraInfo = GetMessageExtraInfo() } };
|
||||
var union = new InputUnion() { mi = new MOUSEINPUT() { dwFlags = MOUSEEVENTF.ABSOLUTE | mouseEvent | MOUSEEVENTF.VIRTUALDESK, dx = (int)normalizedX, dy = (int)normalizedY, time = 0, mouseData = 0, dwExtraInfo = GetMessageExtraInfo() } };
|
||||
var input = new INPUT() { type = InputType.MOUSE, U = union };
|
||||
SendInput(1, new INPUT[] { input }, INPUT.Size);
|
||||
});
|
||||
@ -137,34 +169,6 @@ namespace Remotely.Desktop.Win.Services
|
||||
});
|
||||
}
|
||||
|
||||
public void SendRightMouseDown(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
var xyPercent = GetAbsolutePercentFromRelativePercent(percentX, percentY, viewer.Capturer);
|
||||
// Coordinates must be normalized. The bottom-right coordinate is mapped to 65535.
|
||||
var normalizedX = xyPercent.Item1 * 65535D;
|
||||
var normalizedY = xyPercent.Item2 * 65535D;
|
||||
var union = new InputUnion() { mi = new MOUSEINPUT() { dwFlags = MOUSEEVENTF.ABSOLUTE | MOUSEEVENTF.RIGHTDOWN | MOUSEEVENTF.VIRTUALDESK, dx = (int)normalizedX, dy = (int)normalizedY, time = 0, mouseData = 0, dwExtraInfo = GetMessageExtraInfo() } };
|
||||
var input = new INPUT() { type = InputType.MOUSE, U = union };
|
||||
SendInput(1, new INPUT[] { input }, INPUT.Size);
|
||||
});
|
||||
}
|
||||
|
||||
public void SendRightMouseUp(double percentX, double percentY, Viewer viewer)
|
||||
{
|
||||
TryOnInputDesktop(() =>
|
||||
{
|
||||
var xyPercent = GetAbsolutePercentFromRelativePercent(percentX, percentY, viewer.Capturer);
|
||||
// Coordinates must be normalized. The bottom-right coordinate is mapped to 65535.
|
||||
var normalizedX = xyPercent.Item1 * 65535D;
|
||||
var normalizedY = xyPercent.Item2 * 65535D;
|
||||
var union = new InputUnion() { mi = new MOUSEINPUT() { dwFlags = MOUSEEVENTF.ABSOLUTE | MOUSEEVENTF.RIGHTUP | MOUSEEVENTF.VIRTUALDESK, dx = (int)normalizedX, dy = (int)normalizedY, time = 0, mouseData = 0, dwExtraInfo = GetMessageExtraInfo() } };
|
||||
var input = new INPUT() { type = InputType.MOUSE, U = union };
|
||||
SendInput(1, new INPUT[] { input }, INPUT.Size);
|
||||
});
|
||||
}
|
||||
|
||||
public void SendText(string transferText)
|
||||
{
|
||||
TryOnInputDesktop(() =>
|
||||
|
||||
@ -249,9 +249,6 @@ export function ApplyInputHandlers() {
|
||||
if (currentPointerDevice == "touch") {
|
||||
return;
|
||||
}
|
||||
if (e.button != 0 && e.button != 2) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
var percentX = e.offsetX / viewer.clientWidth;
|
||||
var percentY = e.offsetY / viewer.clientHeight;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user