Skip to content

Commit

Permalink
adds support for click extensions on osx arm (#58)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Hanna <[email protected]>
  • Loading branch information
cdhanna and chrisbeamable authored Aug 19, 2024
1 parent d98cb96 commit 7bc2c09
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Desktop.Robot/Clicks/Clicks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public static IClick RightButton(int delay)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return new OSX.RightClick(delay);
return RuntimeInformation.ProcessArchitecture == Architecture.Arm64
? new OSX.ARM.RightClick(delay)
: new OSX.RightClick(delay);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand All @@ -44,7 +46,9 @@ public static IClick LeftButton(int delay)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return new OSX.LeftClick(delay);
return RuntimeInformation.ProcessArchitecture == Architecture.Arm64
? new OSX.ARM.LeftClick(delay)
: new OSX.LeftClick(delay);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand All @@ -64,7 +68,9 @@ public static IClick MiddleButton(int delay)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return new OSX.MiddleClick(delay);
return RuntimeInformation.ProcessArchitecture == Architecture.Arm64
? new OSX.ARM.MiddleClick(delay)
: new OSX.MiddleClick(delay);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand Down
27 changes: 27 additions & 0 deletions Desktop.Robot/Clicks/OSX/ARM/Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Runtime.InteropServices;

namespace Desktop.Robot.Clicks.OSX.ARM
{
static class Common
{
[DllImport("./osx_arm.os", EntryPoint = "rightMouseUp")]
internal static extern void RightClickUp(uint x, uint y);

[DllImport("./osx_arm.os", EntryPoint = "rightMouseDown")]
internal static extern void RightClickDown(uint x, uint y);


[DllImport("./osx_arm.os", EntryPoint = "leftMouseUp")]
internal static extern void LeftClickUp(uint x, uint y);

[DllImport("./osx_arm.os", EntryPoint = "leftMouseDown")]
internal static extern void LeftClickDown(uint x, uint y);


[DllImport("./osx_arm.os", EntryPoint = "otherMouseUp")]
internal static extern void OtherClickUp(uint x, uint y);

[DllImport("./osx_arm.os", EntryPoint = "otherMouseDown")]
internal static extern void OtherClickDown(uint x, uint y);
}
}
17 changes: 17 additions & 0 deletions Desktop.Robot/Clicks/OSX/ARM/LeftClick.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Desktop.Robot.Clicks.OSX.ARM
{
internal record LeftClick(int delay) : IClick
{
public int Delay => delay;

public void ExecuteMouseDown(MouseContext context)
{
Common.LeftClickDown((uint)context.Position.X, (uint)context.Position.Y);
}

public void ExecuteMouseUp(MouseContext context)
{
Common.LeftClickUp((uint)context.Position.X, (uint)context.Position.Y);
}
}
}
17 changes: 17 additions & 0 deletions Desktop.Robot/Clicks/OSX/ARM/MiddleClick.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Desktop.Robot.Clicks.OSX.ARM
{
internal record MiddleClick(int delay) : IClick
{
public int Delay => delay;

public void ExecuteMouseDown(MouseContext context)
{
Common.OtherClickDown((uint)context.Position.X, (uint)context.Position.Y);
}

public void ExecuteMouseUp(MouseContext context)
{
Common.OtherClickUp((uint)context.Position.X, (uint)context.Position.Y);
}
}
}
17 changes: 17 additions & 0 deletions Desktop.Robot/Clicks/OSX/ARM/RightClick.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Desktop.Robot.Clicks.OSX.ARM
{
internal record RightClick(int delay) : IClick
{
public int Delay => delay;

public void ExecuteMouseDown(MouseContext context)
{
Common.RightClickDown((uint)context.Position.X, (uint)context.Position.Y);
}

public void ExecuteMouseUp(MouseContext context)
{
Common.RightClickUp((uint)context.Position.X, (uint)context.Position.Y);
}
}
}

0 comments on commit 7bc2c09

Please sign in to comment.