Cmdpal Powertoys Extension: Support mouse without borders easy mouse … (#45350)

## Description

You don't have to go to powertoys settings to 
* toggle the mouse move from machine to another
* you can trigger reconnect when connection lost from cmdpal
* You can toggle whether kbm is turning on or not from cmdpal

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Add several missing cmd to powretoys cmdpal extension


<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed


https://github.com/user-attachments/assets/9ea019f7-988b-4542-afc5-a80f0fc99ef8

For the kbm toggle, when it's off, kbm will not map anything, if it's
on, kbm will take effect

For the mouse without borders, add these two functionality as command
<img width="1182" height="158" alt="image"
src="https://github.com/user-attachments/assets/27f526b1-9c91-4923-be6c-e505673f5892"
/>

And verified for the two command, works as expected
This commit is contained in:
Kai Tao
2026-03-09 10:25:11 +08:00
committed by GitHub
parent f6b0996c9b
commit 3d69785ca4
28 changed files with 574 additions and 24 deletions

View File

@@ -229,6 +229,7 @@ namespace MouseWithoutBorders.Class
if (!Common.RunOnLogonDesktop)
{
StartSettingSyncThread();
CommandEventHandler.StartListening();
}
Application.EnableVisualStyles();

View File

@@ -0,0 +1,114 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Threading;
using MouseWithoutBorders.Class;
using PowerToys.Interop;
namespace MouseWithoutBorders.Core
{
/// <summary>
/// Handles command events from external sources (e.g., Command Palette).
/// Uses named events for inter-process communication, following the same pattern as other PowerToys modules.
/// </summary>
internal static class CommandEventHandler
{
private static CancellationTokenSource _cancellationTokenSource;
/// <summary>
/// Starts listening for command events on background threads.
/// </summary>
public static void StartListening()
{
_cancellationTokenSource = new CancellationTokenSource();
CancellationToken exitToken = _cancellationTokenSource.Token;
// Start listener for Toggle Easy Mouse event
StartEventListener(Constants.MWBToggleEasyMouseEvent(), ToggleEasyMouse, exitToken);
// Start listener for Reconnect event
StartEventListener(Constants.MWBReconnectEvent(), Reconnect, exitToken);
}
/// <summary>
/// Stops listening for command events.
/// </summary>
public static void StopListening()
{
_cancellationTokenSource?.Cancel();
_cancellationTokenSource?.Dispose();
_cancellationTokenSource = null;
}
private static void StartEventListener(string eventName, Action callback, CancellationToken cancel)
{
new System.Threading.Thread(() =>
{
try
{
using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
WaitHandle[] waitHandles = new WaitHandle[] { cancel.WaitHandle, eventHandle };
while (!cancel.IsCancellationRequested)
{
int result = WaitHandle.WaitAny(waitHandles);
if (result == 1)
{
// Execute callback on UI thread using Common.DoSomethingInUIThread
Common.DoSomethingInUIThread(callback);
}
else
{
// Cancellation requested
return;
}
}
}
catch (Exception ex)
{
Logger.Log($"Error in event listener for {eventName}: {ex.Message}");
}
})
{ IsBackground = true, Name = $"MWB-{eventName}-Listener" }.Start();
}
/// <summary>
/// Toggles Easy Mouse between Enabled and Disabled states.
/// This is the same logic used by the hotkey handler.
/// </summary>
public static void ToggleEasyMouse()
{
if (Common.RunOnLogonDesktop || Common.RunOnScrSaverDesktop)
{
return;
}
EasyMouseOption easyMouseOption = (EasyMouseOption)Setting.Values.EasyMouse;
if (easyMouseOption is EasyMouseOption.Disable or EasyMouseOption.Enable)
{
Setting.Values.EasyMouse = (int)(easyMouseOption == EasyMouseOption.Disable ? EasyMouseOption.Enable : EasyMouseOption.Disable);
Common.ShowToolTip($"Easy Mouse has been toggled to [{(EasyMouseOption)Setting.Values.EasyMouse}].", 3000);
Logger.Log($"Easy Mouse toggled to {(EasyMouseOption)Setting.Values.EasyMouse} via command event.");
}
}
/// <summary>
/// Initiates a reconnection attempt to all machines.
/// This is the same logic used by the hotkey handler.
/// </summary>
public static void Reconnect()
{
Common.ShowToolTip("Reconnecting...", 2000);
Common.LastReconnectByHotKeyTime = Common.GetTick();
InitAndCleanup.PleaseReopenSocket = InitAndCleanup.REOPEN_WHEN_HOTKEY;
Logger.Log("Reconnect initiated via command event.");
}
}
}

View File

@@ -218,6 +218,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
<ProjectReference Include="..\..\..\common\interop\PowerToys.Interop.vcxproj" />
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
</ItemGroup>
<ItemGroup>