mirror of
https://github.com/vale981/VoiDPlugins
synced 2025-03-05 09:11:38 -05:00
Merge pull request #2 from X9VoiD:vmulti
Add VMultiMode (Absolute and Relative Modes)
This commit is contained in:
commit
4385f7a0a7
5 changed files with 241 additions and 1 deletions
3
.github/workflows/dotnet-core.yml
vendored
3
.github/workflows/dotnet-core.yml
vendored
|
@ -7,7 +7,7 @@ jobs:
|
|||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
plugin: [MLFilter, OemKill, TouchEmu, WindowsInk]
|
||||
plugin: [MLFilter, OemKill, TouchEmu, WindowsInk, VMultiMode]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
@ -33,5 +33,6 @@ jobs:
|
|||
path: |
|
||||
./build/netcoreapp3.1/${{ matrix.plugin }}/*.dll
|
||||
!./build/netcoreapp3.1/${{ matrix.plugin }}/*.json
|
||||
!./build/netcoreapp3.1/${{ matrix.plugin }}/*.pdb
|
||||
!./build/netcoreapp3.1/${{ matrix.plugin }}/OpenTabletDriver.Plugin.dll
|
||||
!./build/netcoreapp3.1/${{ matrix.plugin }}/Newtonsoft.Json.dll
|
||||
|
|
|
@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TouchEmu", "TouchEmu\TouchE
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsInk", "WindowsInk\WindowsInk.csproj", "{5DDEBB0A-D359-49F4-B1AE-7A13DB28987B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VMultiMode", "VMultiMode\VMultiMode.csproj", "{7D086384-9E50-45A1-BD7A-ECF44CB31223}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -33,6 +35,10 @@ Global
|
|||
{5DDEBB0A-D359-49F4-B1AE-7A13DB28987B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5DDEBB0A-D359-49F4-B1AE-7A13DB28987B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5DDEBB0A-D359-49F4-B1AE-7A13DB28987B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7D086384-9E50-45A1-BD7A-ECF44CB31223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7D086384-9E50-45A1-BD7A-ECF44CB31223}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7D086384-9E50-45A1-BD7A-ECF44CB31223}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7D086384-9E50-45A1-BD7A-ECF44CB31223}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
148
VMultiMode/VMulti.cs
Normal file
148
VMultiMode/VMulti.cs
Normal file
|
@ -0,0 +1,148 @@
|
|||
using System.Numerics;
|
||||
using HidSharp;
|
||||
using OpenTabletDriver.Plugin;
|
||||
using OpenTabletDriver.Plugin.Platform.Pointer;
|
||||
|
||||
namespace VMultiMode
|
||||
{
|
||||
public static class VMulti
|
||||
{
|
||||
public abstract class VMultiReport
|
||||
{
|
||||
public byte VMultiID; // ID to communicate to the Mouse device
|
||||
public byte ReportLength; // Size of the report in bytes.
|
||||
public byte ReportID; // ID of the report.
|
||||
public byte Buttons; // Byte with switches for mouse buttons
|
||||
public abstract byte Size { get; }
|
||||
public abstract byte[] ToBytes();
|
||||
}
|
||||
|
||||
public class VMultiAbsReport : VMultiReport
|
||||
{
|
||||
public ushort X; // X position of the mouse from 0 to 32767
|
||||
public ushort Y; // Y position of the mouse from 0 to 32767
|
||||
public ushort Pressure; // Pressure of the mouse? from 0 to 8191
|
||||
public override byte[] ToBytes()
|
||||
{
|
||||
var bytes = new byte[Size];
|
||||
bytes[0] = VMultiID;
|
||||
bytes[1] = ReportLength;
|
||||
bytes[2] = ReportID;
|
||||
bytes[3] = Buttons;
|
||||
bytes[4] = (byte)(X & 0xFF);
|
||||
bytes[5] = (byte)((X & 0xFF00) >> 8);
|
||||
bytes[6] = (byte)(Y & 0xFF);
|
||||
bytes[7] = (byte)((Y & 0xFF00) >> 8);
|
||||
bytes[8] = (byte)(Pressure & 0xFF);
|
||||
bytes[9] = (byte)((Pressure & 0xFF00) >> 8);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public override byte Size => 10;
|
||||
}
|
||||
|
||||
public class VMultiRelReport : VMultiReport
|
||||
{
|
||||
public byte X; // X position of the mouse from -127 to 127
|
||||
public byte Y; // Y position of the mouse from -127 to 127
|
||||
public byte WheelPos; // Wheel position of the mouse from -127 to 127
|
||||
public override byte[] ToBytes()
|
||||
{
|
||||
var bytes = new byte[Size];
|
||||
bytes[0] = VMultiID;
|
||||
bytes[1] = ReportLength;
|
||||
bytes[2] = ReportID;
|
||||
bytes[3] = Buttons;
|
||||
bytes[4] = X;
|
||||
bytes[5] = Y;
|
||||
bytes[6] = WheelPos;
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public override byte Size => 7;
|
||||
}
|
||||
|
||||
public enum ButtonMask : int
|
||||
{
|
||||
Left = 1,
|
||||
Right = 2,
|
||||
Middle = 4,
|
||||
}
|
||||
|
||||
|
||||
public class VMultiHandler<T> where T : VMultiReport, new()
|
||||
{
|
||||
protected T Report;
|
||||
protected HidStream VMultiDev;
|
||||
protected Area ScreenArea;
|
||||
|
||||
protected void Init(string Name, byte ReportID)
|
||||
{
|
||||
Report = new T()
|
||||
{
|
||||
VMultiID = 0x40,
|
||||
ReportID = ReportID
|
||||
};
|
||||
|
||||
Report.ReportLength = Report.Size;
|
||||
|
||||
VMultiDev = null;
|
||||
foreach (var device in DeviceList.Local.GetHidDevices(productID: 47820))
|
||||
{
|
||||
if (device.GetMaxOutputReportLength() == 65 && device.GetMaxInputReportLength() == 65)
|
||||
{
|
||||
device.TryOpen(out VMultiDev);
|
||||
if (VMultiDev == null)
|
||||
{
|
||||
Log.Write(Name, "Cannot find VirtualHID", LogLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void MouseDown(MouseButton button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case MouseButton.Left:
|
||||
EnableBit(ButtonMask.Left);
|
||||
break;
|
||||
case MouseButton.Right:
|
||||
EnableBit(ButtonMask.Right);
|
||||
break;
|
||||
case MouseButton.Middle:
|
||||
EnableBit(ButtonMask.Middle);
|
||||
break;
|
||||
}
|
||||
VMultiDev.Write(Report.ToBytes());
|
||||
}
|
||||
|
||||
public void MouseUp(MouseButton button)
|
||||
{
|
||||
switch (button)
|
||||
{
|
||||
case MouseButton.Left:
|
||||
DisableBit(ButtonMask.Left);
|
||||
break;
|
||||
case MouseButton.Right:
|
||||
DisableBit(ButtonMask.Right);
|
||||
break;
|
||||
case MouseButton.Middle:
|
||||
DisableBit(ButtonMask.Middle);
|
||||
break;
|
||||
}
|
||||
VMultiDev.Write(Report.ToBytes());
|
||||
}
|
||||
|
||||
private void EnableBit(ButtonMask mask)
|
||||
{
|
||||
Report.Buttons = (byte)(Report.Buttons | (int)mask);
|
||||
}
|
||||
|
||||
private void DisableBit(ButtonMask mask)
|
||||
{
|
||||
Report.Buttons = (byte)(Report.Buttons & ~(int)mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
66
VMultiMode/VMultiMode.cs
Normal file
66
VMultiMode/VMultiMode.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System.Numerics;
|
||||
using OpenTabletDriver.Plugin;
|
||||
using OpenTabletDriver.Plugin.Attributes;
|
||||
using OpenTabletDriver.Plugin.Output;
|
||||
using OpenTabletDriver.Plugin.Platform.Pointer;
|
||||
using static VMultiMode.VMulti;
|
||||
|
||||
namespace VMultiMode
|
||||
{
|
||||
internal static class VMultiState
|
||||
{
|
||||
public static VMultiAbsHandler AbsHandler = null;
|
||||
public static VMultiRelHandler RelHandler = null;
|
||||
}
|
||||
|
||||
[PluginName("VMulti Absolute Output Mode"), SupportedPlatform(PluginPlatform.Windows)]
|
||||
public class VMultiAbsMode : AbsoluteOutputMode
|
||||
{
|
||||
public override IVirtualTablet VirtualTablet => VMultiState.AbsHandler ?? new VMultiAbsHandler(Output);
|
||||
}
|
||||
|
||||
[PluginName("VMulti Relative Output Mode"), SupportedPlatform(PluginPlatform.Windows)]
|
||||
public class VMultiRelMode : AbsoluteOutputMode
|
||||
{
|
||||
public override IVirtualTablet VirtualTablet => VMultiState.RelHandler ?? new VMultiRelHandler(Output);
|
||||
}
|
||||
|
||||
public class VMultiAbsHandler : VMultiHandler<VMultiAbsReport>, IVirtualTablet
|
||||
{
|
||||
public VMultiAbsHandler(Area screenArea)
|
||||
{
|
||||
VMultiState.AbsHandler = this;
|
||||
Init("VMultiAbs", 0x09);
|
||||
ScreenArea = screenArea;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 pos)
|
||||
{
|
||||
Report.X = (ushort)(pos.X / ScreenArea.Width * 32767);
|
||||
Report.Y = (ushort)(pos.Y / ScreenArea.Height * 32767);
|
||||
VMultiDev.Write(Report.ToBytes());
|
||||
}
|
||||
}
|
||||
|
||||
public class VMultiRelHandler : VMultiHandler<VMultiRelReport>, IVirtualTablet
|
||||
{
|
||||
ushort prevX, prevY;
|
||||
public VMultiRelHandler(Area screenArea)
|
||||
{
|
||||
VMultiState.RelHandler = this;
|
||||
Init("VMultiRel", 0x04);
|
||||
ScreenArea = screenArea;
|
||||
}
|
||||
|
||||
public void SetPosition(Vector2 pos)
|
||||
{
|
||||
var X = (ushort)pos.X;
|
||||
var Y = (ushort)pos.Y;
|
||||
Report.X = (byte)(X - prevX);
|
||||
Report.Y = (byte)(Y - prevY);
|
||||
prevX = X;
|
||||
prevY = Y;
|
||||
VMultiDev.Write(Report.ToBytes());
|
||||
}
|
||||
}
|
||||
}
|
19
VMultiMode/VMultiMode.csproj
Normal file
19
VMultiMode/VMultiMode.csproj
Normal file
|
@ -0,0 +1,19 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netcoreapp3.1; net5.0</TargetFrameworks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<DebugType>none</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="HidSharpCore" Version="1.0.1" />
|
||||
<ProjectReference Include="../.modules/OpenTabletDriver/OpenTabletDriver.Plugin/OpenTabletDriver.Plugin.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Add table
Reference in a new issue