Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Example/bin/Debug/net8.0/Example.dll",
"args": [],
"cwd": "${workspaceFolder}/Example",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
36 changes: 36 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,42 @@
"isDefault": true
},
"detail": "Task generated by Debugger."
},
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/Desktop.Robot.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/Desktop.Robot.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/Desktop.Robot.sln"
],
"problemMatcher": "$msCompile"
}
],
"version": "2.0.0"
Expand Down
13 changes: 7 additions & 6 deletions Desktop.Robot.TestApp/Desktop.Robot.TestApp.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From your PR text, it doesn't seem intentional that you meant to change the target framework and all these versions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right! The changing of the target framework shouldn't have been included into this PR. But I'm always using the latest version of .NET in my projects and I think, this project should also be upgraded (with support for net6.0, net7.0, net8.0). But of course, as you say, this would also need some adaptions to the nuget pipelines and it would be better to do this in a separate PR.

<WarnOn>3390;$(WarnOn)</WarnOn>
</PropertyGroup>
<ItemGroup>
Expand All @@ -14,10 +14,11 @@
<ProjectReference Include="..\Desktop.Robot\Desktop.Robot.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="0.10.18" />
<PackageReference Include="Expecto" Version="9.0.4" />
<PackageReference Include="Expecto.Diff" Version="9.0.4" />
<PackageReference Include="Expecto.FsCheck" Version="9.0.4" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
<PackageReference Include="Expecto" Version="10.2.1" />
<PackageReference Include="Expecto.Diff" Version="10.2.1" />
<PackageReference Include="Expecto.FsCheck" Version="10.2.1" />
<PackageReference Include="FSharp.Control.Reactive" Version="5.0.5" />
</ItemGroup>
<PackageReference Include="System.Reactive" Version="6.0.1" />
</ItemGroup>
</Project>
28 changes: 14 additions & 14 deletions Desktop.Robot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Desktop.Robot", "Desktop.Ro
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.csproj", "{9B7B0021-B931-4488-84E7-D4DD4C74A555}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Desktop.Robot.TestApp", "Desktop.Robot.TestApp\Desktop.Robot.TestApp.fsproj", "{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}"
EndProject
#Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Desktop.Robot.TestApp", "Desktop.Robot.TestApp\Desktop.Robot.TestApp.fsproj", "{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}"
#EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -46,17 +46,17 @@ Global
{9B7B0021-B931-4488-84E7-D4DD4C74A555}.Release|x64.Build.0 = Release|Any CPU
{9B7B0021-B931-4488-84E7-D4DD4C74A555}.Release|x86.ActiveCfg = Release|Any CPU
{9B7B0021-B931-4488-84E7-D4DD4C74A555}.Release|x86.Build.0 = Release|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|x64.ActiveCfg = Debug|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|x64.Build.0 = Debug|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|x86.ActiveCfg = Debug|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|x86.Build.0 = Debug|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|Any CPU.Build.0 = Release|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|x64.ActiveCfg = Release|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|x64.Build.0 = Release|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|x86.ActiveCfg = Release|Any CPU
{05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|x86.Build.0 = Release|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|x64.ActiveCfg = Debug|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|x64.Build.0 = Debug|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|x86.ActiveCfg = Debug|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Debug|x86.Build.0 = Debug|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|Any CPU.Build.0 = Release|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|x64.ActiveCfg = Release|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|x64.Build.0 = Release|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|x86.ActiveCfg = Release|Any CPU
# {05C9255A-C2BE-4F80-9EA1-9038DE424FB4}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
17 changes: 10 additions & 7 deletions Desktop.Robot/Desktop.Robot.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.5.0</Version>
<TargetFramework>net8.0</TargetFramework>
<Version>1.5.2</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Lucas Simas</Authors>
<Description>A library used to control your mouse and keyboard programmatically in .NET Core</Description>
<Authors>Lucas Simas, Christoph Döllinger</Authors>
<Description>A library used to control your mouse and keyboard programmatically in .NET Core
Updated to .NET 8</Description>
<PackageProjectUrl>https://lucassklp.github.io/Desktop.Robot/</PackageProjectUrl>
<RepositoryUrl>https://github.com/lucassklp/Desktop.Robot</RepositoryUrl>
<RepositoryUrl>https://github.com/MrDoe/Desktop.Robot</RepositoryUrl>
<PackageIcon>logo.mini.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageId>$(AssemblyName)_Net8_v</PackageId>
<Product>$(AssemblyName)_Net8_v</Product>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,8 +22,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.Drawing.Common" Version="8.0.6" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
38 changes: 33 additions & 5 deletions Desktop.Robot/Linux/Robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,38 @@ public override void KeyPress(Key key)
public override void KeyPress(char key)
{
ApplyAutoDelay();
var flags = char.IsUpper(key) ? (1 << 0) : 0;
pressKey(key, true, flags);
pressKey(key, false, flags);
// Get the high order byte of the result to check for Ctrl and Alt keys
var highOrderByte = char.IsUpper(key) ? (1 << 0) : 0;

// Check if the key is uppercase or if AltGr (Ctrl + Alt) is needed
if ((highOrderByte & 1) == 1) // Shift
{
KeyDown(Key.Shift);
}
if ((highOrderByte & 2) == 2) // Ctrl
{
KeyDown(Key.Control);
}
if ((highOrderByte & 4) == 4) // Alt
{
KeyDown(Key.Alt);
}

pressKey(key, true, highOrderByte);
pressKey(key, false, highOrderByte);

if ((highOrderByte & 1) == 1) // Shift
{
KeyUp(Key.Shift);
}
if ((highOrderByte & 2) == 2) // Ctrl
{
KeyUp(Key.Control);
}
if ((highOrderByte & 4) == 4) // Alt
{
KeyUp(Key.Alt);
}
}

public override void KeyUp(Key key)
Expand All @@ -69,7 +98,6 @@ public override void MouseMove(int x, int y)
moveMouse(x, y);
}


public override void MouseScroll(int value)
{
ApplyAutoDelay();
Expand All @@ -84,7 +112,7 @@ public override void MouseScroll(int value, TimeSpan duration)
public override void MouseScroll(int value, TimeSpan duration, int steps)
{
ApplyAutoDelay();
for (int i = 0; i < steps; i++)
for (int i = 0; i < steps; ++i)
{
DoMouseScroll(value / steps, Convert.ToInt32(duration.TotalMilliseconds) / steps);
}
Expand Down
44 changes: 38 additions & 6 deletions Desktop.Robot/Windows/Robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

namespace Desktop.Robot.Windows
{
Expand Down Expand Up @@ -42,13 +43,44 @@ public override void KeyPress(Key key)

public override void KeyPress(char key)
{
ApplyAutoDelay();
var keycode = (byte)VkKeyScan(key);
keybd_event(keycode, 0, 0, 0);
keybd_event(keycode, 0, 2, 0);
}
ApplyAutoDelay();
short result = VkKeyScan(key);

// Get the high order byte of the result to check for Ctrl and Alt keys
var highOrderByte = (result >> 8) & 0xFF;

// Check if the key is uppercase or if AltGr (Ctrl + Alt) is needed
if ((highOrderByte & 1) == 1) // Shift
{
KeyDown(Key.Shift);
}
if ((highOrderByte & 2) == 2) // Ctrl
{
KeyDown(Key.Control);
}
if ((highOrderByte & 4) == 4) // Alt
{
KeyDown(Key.Alt);
}

keybd_event((byte)result, 0, 0, 0); // key down
keybd_event((byte)result, 0, 2, 0); // key up

if ((highOrderByte & 1) == 1) // Shift
{
KeyUp(Key.Shift);
}
if ((highOrderByte & 2) == 2) // Ctrl
{
KeyUp(Key.Control);
}
if ((highOrderByte & 4) == 4) // Alt
{
KeyUp(Key.Alt);
}
}

public override void KeyUp(Key key)
public override void KeyUp(Key key)
{
ApplyAutoDelay();
var metadata = key.GetKeycode();
Expand Down
2 changes: 1 addition & 1 deletion Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ I made this library because the dotnet SDK doesn't support simulation of mouse a
If you are using Package Manager:

```bash
Install-Package Desktop.Robot -Version 1.5.0
Install-Package Desktop.Robot -Version 1.5.2
```

If you are using .NET CLI

```bash
dotnet add package Desktop.Robot --version 1.5.0
dotnet add package Desktop.Robot --version 1.5.2
```


Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Desktop.Robot" Version="1.4.0" />
<PackageReference Include="Desktop.Robot" Version="1.5.0" />
</ItemGroup>

</Project>