Skip to content
Closed
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
59 changes: 59 additions & 0 deletions .github/workflows/build-signed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build signed installer (self-signed)

on:
workflow_dispatch:
push:
branches: [ "claude/target-window" ]

permissions:
contents: read

jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v7

- name: Setup WinApp CLI
uses: microsoft/setup-WinAppCli@v0.3

- name: Create the app package
run: winapp pack AuraClick\AuraClick.csproj -c Debug --arch x86 --arch x64 --arch arm64 --output AuraClick.msixbundle

- name: Create certificate and sign
shell: pwsh
run: |
# Subject must match the Publisher in Package.appxmanifest
$subject = ([xml](Get-Content AuraClick\Package.appxmanifest)).Package.Identity.Publisher
$pwd = ConvertTo-SecureString -String "auraclick" -Force -AsPlainText
$cert = New-SelfSignedCertificate -Type Custom -Subject $subject -KeyUsage DigitalSignature `
-FriendlyName "AuraClick mod" -CertStoreLocation "Cert:\CurrentUser\My" `
-TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")
Export-PfxCertificate -Cert $cert -FilePath cert.pfx -Password $pwd | Out-Null
Export-Certificate -Cert $cert -FilePath AuraClick-mod.cer | Out-Null
$signtool = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\bin\*\x64\signtool.exe" |
Sort-Object FullName | Select-Object -Last 1
& $signtool.FullName sign /fd SHA256 /f cert.pfx /p auraclick AuraClick.msixbundle
if ($LASTEXITCODE) { exit $LASTEXITCODE }
Remove-Item cert.pfx

- name: Write install script
shell: pwsh
run: |
@'
# Right-click > Run with PowerShell. Needs Administrator (it trusts the certificate once).
$dir = Split-Path -Parent $MyInvocation.MyCommand.Path
Import-Certificate -FilePath "$dir\AuraClick-mod.cer" -CertStoreLocation Cert:\LocalMachine\TrustedPeople | Out-Null
Add-AppxPackage -Path "$dir\AuraClick.msixbundle"
Write-Host "Installed. Find 'Aura Click' in the Start menu."
'@ | Set-Content Install.ps1

- name: Upload installer
uses: actions/upload-artifact@v7
with:
name: AuraClick-mod-installer
path: |
AuraClick.msixbundle
AuraClick-mod.cer
Install.ps1
if-no-files-found: error
31 changes: 30 additions & 1 deletion AuraClick/Helpers/AutoClicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public static class AutoClicker
/// </summary>
public static int ClickDelayOffset { get; set; } = 10;

/// <summary>
/// Gets or sets the handle of the window to click in, or 0 to click wherever the cursor is.
/// When set, the window is brought to the front for each click and the previous window is restored afterwards.
/// </summary>
public static nint TargetWindow { get; set; }

/// <summary>
/// Gets a value indicating whether the auto clicker is currently running.
/// </summary>
Expand All @@ -95,12 +101,35 @@ public static void Start()
long clickLimit = ClickAmountEnabled ? ClickAmount : long.MaxValue;
TimeSpan delay = TimeSpan.FromHours(HoursDelay, MinutesDelay, SecondsDelay, MillisecondsDelay);
int maxOffset = ClickDelayOffsetEnabled ? Math.Max(0, ClickDelayOffset) : 0;
nint target = TargetWindow;

_ = Task.Run(async () =>
{
for (long clicks = 1; !cts.IsCancellationRequested; clicks++)
{
_ = PInvoke.SendInput(click, Marshal.SizeOf<INPUT>());
if (target != 0)
{
if (!WindowHelper.Exists(target))
{
// Target window was closed
cts.Cancel();
ClickLimitReached?.Invoke(null, EventArgs.Empty);
return;
}

// Games ignore background input, so focus the window, press, hold briefly, release, then go back
nint previous = WindowHelper.BringToFront(target);
await Task.Delay(80).ConfigureAwait(false);
_ = PInvoke.SendInput(click.AsSpan(0, 1), Marshal.SizeOf<INPUT>());
await Task.Delay(60).ConfigureAwait(false);
_ = PInvoke.SendInput(click.AsSpan(1, 1), Marshal.SizeOf<INPUT>());
WindowHelper.Restore(previous, target);
}
else
{
_ = PInvoke.SendInput(click, Marshal.SizeOf<INPUT>());
}

if (clicks >= clickLimit)
{
cts.Cancel();
Expand Down
164 changes: 164 additions & 0 deletions AuraClick/Helpers/WindowHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using System.Runtime.InteropServices;
using System.Text;

namespace AuraClick.Helpers;

/// <summary>
/// A top-level window the auto clicker can target.
/// </summary>
public sealed class WindowEntry(nint handle, string title)
{
/// <summary>
/// Gets the window handle.
/// </summary>
public nint Handle { get; } = handle;

/// <summary>
/// Gets the window title.
/// </summary>
public string Title { get; } = title;

/// <inheritdoc />
public override string ToString() => Title;
}

/// <summary>
/// Helpers for listing top-level windows and bringing one to the foreground.
/// </summary>
public static class WindowHelper
{
private const int SwRestore = 9;
private const int DwmaCloaked = 14;

private delegate bool EnumWindowsProc(nint hWnd, nint lParam);

[DllImport("user32.dll")]
private static extern bool EnumWindows(EnumWindowsProc callback, nint lParam);

[DllImport("user32.dll")]
private static extern bool IsWindowVisible(nint hWnd);

[DllImport("user32.dll")]
private static extern bool IsWindow(nint hWnd);

[DllImport("user32.dll")]
private static extern bool IsIconic(nint hWnd);

[DllImport("user32.dll")]
private static extern bool ShowWindow(nint hWnd, int nCmdShow);

[DllImport("user32.dll")]
private static extern nint GetForegroundWindow();

[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(nint hWnd);

[DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId(nint hWnd, out uint processId);

[DllImport("user32.dll")]
private static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern int GetWindowTextLength(nint hWnd);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern int GetWindowText(nint hWnd, StringBuilder text, int maxCount);

[DllImport("kernel32.dll")]
private static extern uint GetCurrentThreadId();

[DllImport("dwmapi.dll")]
private static extern int DwmGetWindowAttribute(nint hWnd, int attribute, out int value, int size);

/// <summary>
/// Lists visible, titled top-level windows, excluding <paramref name="exclude" />.
/// </summary>
public static List<WindowEntry> GetOpenWindows(nint exclude)
{
List<WindowEntry> result = [];
_ = EnumWindows((hWnd, _) =>
{
if (hWnd == exclude || !IsWindowVisible(hWnd))
{
return true;
}

// Skip hidden UWP shells that report as visible but are cloaked
if (DwmGetWindowAttribute(hWnd, DwmaCloaked, out int cloaked, sizeof(int)) == 0 && cloaked != 0)
{
return true;
}

int length = GetWindowTextLength(hWnd);
if (length <= 0)
{
return true;
}

StringBuilder sb = new(length + 1);
_ = GetWindowText(hWnd, sb, sb.Capacity);
string title = sb.ToString().Trim();
if (title.Length > 0)
{
result.Add(new WindowEntry(hWnd, title));
}

return true;
}, 0);

result.Sort((a, b) => string.Compare(a.Title, b.Title, StringComparison.OrdinalIgnoreCase));
return result;
}

/// <summary>
/// Returns whether the window still exists.
/// </summary>
public static bool Exists(nint hWnd) => hWnd != 0 && IsWindow(hWnd);

/// <summary>
/// Brings the window to the foreground and returns the previously active window.
/// </summary>
public static nint BringToFront(nint target)
{
nint previous = GetForegroundWindow();
if (previous == target)
{
return previous;
}

if (IsIconic(target))
{
_ = ShowWindow(target, SwRestore);
}

ForceForeground(target, previous);
return previous;
}

/// <summary>
/// Returns focus to the window that was active before <see cref="BringToFront" />.
/// </summary>
public static void Restore(nint previous, nint target)
{
if (previous != 0 && previous != target && IsWindow(previous))
{
ForceForeground(previous, GetForegroundWindow());
}
}

private static void ForceForeground(nint window, nint currentForeground)
{
uint foregroundThread = currentForeground != 0 ? GetWindowThreadProcessId(currentForeground, out _) : 0;
uint thisThread = GetCurrentThreadId();
bool attached = foregroundThread != 0 && foregroundThread != thisThread
&& AttachThreadInput(thisThread, foregroundThread, true);

_ = SetForegroundWindow(window);

if (attached)
{
_ = AttachThreadInput(thisThread, foregroundThread, false);
}
}
}
26 changes: 25 additions & 1 deletion AuraClick/Pages/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>

<Page
x:Class="AuraClick.MainPage"
Expand Down Expand Up @@ -44,6 +44,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
Expand Down Expand Up @@ -193,6 +194,29 @@
IsEnabled="{x:Bind (x:Boolean)ClickOffsetCheckBox.IsChecked}" />
</Grid>
</StackPanel>

<!-- Target window -->
<StackPanel
Grid.Row="3"
Grid.ColumnSpan="2"
Spacing="{StaticResource HeaderSpacing}">
<dev:IsEnabledTextBlock Text="Target window (focused for each click, then your previous app returns)" />
<Grid ColumnSpacing="{StaticResource ControlSpacing}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ComboBox
x:Name="TargetWindowComboBox"
HorizontalAlignment="Stretch"
SelectionChanged="TargetWindowComboBox_SelectionChanged" />
<Button
x:Name="RefreshWindowsButton"
Grid.Column="1"
Click="RefreshWindowsButton_Click"
Content="Refresh" />
</Grid>
</StackPanel>
</Grid>
</ContentControl>

Expand Down
43 changes: 42 additions & 1 deletion AuraClick/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2026 Ryan Luu
// Copyright (C) 2026 Ryan Luu
//
// This file is part of Aura Click.
//
Expand Down Expand Up @@ -155,6 +155,8 @@ private async void MainPage_Loaded(object sender, RoutedEventArgs e)
// Register hotkey
await ApplyHotkeySelectionAsync();

RefreshWindowList();

if (s_settingsPage.IsStartButtonTeachingTipDismissed)
{
return;
Expand Down Expand Up @@ -286,6 +288,45 @@ private void StartToggleButton_Unchecked(object sender, RoutedEventArgs e)
}
}

/// <summary>
/// Placeholder item meaning "click wherever the cursor is".
/// </summary>
private const string NoTargetLabel = "None (click wherever the cursor is)";

/// <summary>
/// Reloads the list of open windows, keeping the current selection or preferring Minecraft.
/// </summary>
private void RefreshWindowList()
{
nint previous = AutoClicker.TargetWindow;
nint self = WindowNative.GetWindowHandle(App.MainWindow);
List<WindowEntry> windows = WindowHelper.GetOpenWindows(self);

List<object> items = [NoTargetLabel, .. windows];
TargetWindowComboBox.ItemsSource = items;

object? selected = windows.FirstOrDefault(w => w.Handle == previous);
selected ??= windows.FirstOrDefault(w => w.Title.Equals("Minecraft", StringComparison.Ordinal))
?? windows.FirstOrDefault(w => w.Title.Contains("Minecraft", StringComparison.OrdinalIgnoreCase));
TargetWindowComboBox.SelectedItem = selected ?? items[0];
}

/// <summary>
/// Handles the SelectionChanged event of the TargetWindowComboBox control.
/// </summary>
private void TargetWindowComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
AutoClicker.TargetWindow = TargetWindowComboBox.SelectedItem is WindowEntry entry ? entry.Handle : 0;
}

/// <summary>
/// Handles the Click event of the RefreshWindowsButton control.
/// </summary>
private void RefreshWindowsButton_Click(object sender, RoutedEventArgs e)
{
RefreshWindowList();
}

/// <summary>
/// Handles the Click event of the SettingsButton control.
/// </summary>
Expand Down