Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New PowerToy] OCR PowerToy (#19172)
* Init commit * Fix unintended GUID change of Microsoft.PowerToys.Run.Plugin.TimeZone.UnitTests * Region and click word working * Code style * Close even when there is no result from the OCR * Fix spelling concerns, and make overlay black to match snipping tool * increase opacity of overlay to match snipping tool * Code Style and cleanup * Code style * Create Logos and hook them into the project file * Make the PowerOCR VCXProj more like Awake VCXProj * Rename MainWindow to OCROverlay * Add WindowUtilities and WindowForms * Remove fsg to fix spelling error * launch OCR Overlay on every screen * Add PowerOCR to Runner Main.cpp * Add PowerOCR Settings and Properties * Add PowerOcrViewModel * Fix wrong setting reference in PowerOcrSettingsVM * Try to clean up the Cpp project for PowerOCR * Went to ARM64 was x64 thanks @snickler * Clean up PowerOCR C++ Proj with file refs * Rewrite C++ dllmain comparing to awake * Changes for spelling issues. The rest will stay * Create PowerOcr Settings Page and add to settings shell * Fix PowerOcr Settings * Fix multi-monitor scaling issue * Add close all overlays when escaping * Update src/runner/main.cpp to call correct Power OCR dll Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com> * Update expect.txt * Add many files from Color Picker for hotkey activation * Organize project into helper folder * Use new hotkey activation and keep process alive * Fix bug where scalebmp wasn't working * Add The file headers and dispose app.xaml.cs * Code style changes * Fix bug where PowerOCR was toggling Awake * Unsubscribe from keyboard events making they don't fire twice * Add SndPowerOcrSetting and add to SettingsVM * Trying to make the runner close PowerOCR when runner closes * Fix app_name * Update spellcheck expect * use mutex on PowerOCR app to keep to single instance * Rebuild the module interface using ColorPicker as a template. Process still stays alive. * Fix project names of the module interface * Put app startup args back to 0 like color picker * Runner now finds and enables/disables PowerOCR * remove unneeded item groups from settings proj, per stefansjfw * Add PowerOCR Screenshots * Revert changed project GUID * Add OOBE content for PowerOCR * Keep cursor on one screen since the OCR window does not span screens. * reload settings when activation key is pressed * New screenshots and OOBE text * Add PowerOCR as a case in the settings App.xaml.cs OnLaunched * Settings and OOBE Text Changes * Using using on bitmaps and change OCR overlay to stay open if no result * Keyboard activation is handled is true * Remove unused start PowerOCR OOBE Method * [PowerOCR]Add some telemetry * Add some logging * Don't recreate the OCR overlay Windows more times * Add to BugReportTool to get event viewer errors * Fix wrong comment * Fix another comment * Add files to installer * Add to signing * Don't take Esc away from other apps * Default to Win Shift R * Use low level keyboard hook from runner * Remove esc from local low level keyboard hook * Fix some nits * Default to Win Shift T
- Loading branch information
Showing
64 changed files
with
3,040 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Application | ||
x:Class="PowerOCR.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:PowerOCR" | ||
ShutdownMode="OnExplicitShutdown" | ||
Exit="Application_Exit" | ||
Startup="Application_Startup"> | ||
<Application.Resources /> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// 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.Diagnostics; | ||
using System.Threading; | ||
using System.Windows; | ||
using ManagedCommon; | ||
using PowerOCR.Helpers; | ||
using PowerOCR.Keyboard; | ||
using PowerOCR.Settings; | ||
|
||
namespace PowerOCR; | ||
|
||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App : Application, IDisposable | ||
{ | ||
private KeyboardMonitor? keyboardMonitor; | ||
private EventMonitor? eventMonitor; | ||
private Mutex? _instanceMutex; | ||
private int _powerToysRunnerPid; | ||
|
||
public void Dispose() | ||
{ | ||
GC.SuppressFinalize(this); | ||
keyboardMonitor?.Dispose(); | ||
} | ||
|
||
private void Application_Startup(object sender, StartupEventArgs e) | ||
{ | ||
// allow only one instance of PowerOCR | ||
_instanceMutex = new Mutex(true, @"Local\PowerToys_PowerOCR_InstanceMutex", out bool createdNew); | ||
if (!createdNew) | ||
{ | ||
Logger.LogWarning("Another running PowerOCR instance was detected. Exiting PowerOCR"); | ||
_instanceMutex = null; | ||
Environment.Exit(0); | ||
return; | ||
} | ||
|
||
if (e.Args?.Length > 0) | ||
{ | ||
try | ||
{ | ||
_ = int.TryParse(e.Args[0], out _powerToysRunnerPid); | ||
Logger.LogInfo($"PowerOCR started from the PowerToys Runner. Runner pid={_powerToysRunnerPid}"); | ||
|
||
RunnerHelper.WaitForPowerToysRunner(_powerToysRunnerPid, () => | ||
{ | ||
Logger.LogInfo("PowerToys Runner exited. Exiting PowerOCR"); | ||
Environment.Exit(0); | ||
}); | ||
var userSettings = new UserSettings(new Helpers.ThrottledActionInvoker()); | ||
eventMonitor = new EventMonitor(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine(ex.Message); | ||
} | ||
} | ||
else | ||
{ | ||
Logger.LogInfo($"PowerOCR started detached from PowerToys Runner."); | ||
_powerToysRunnerPid = -1; | ||
var userSettings = new UserSettings(new Helpers.ThrottledActionInvoker()); | ||
keyboardMonitor = new KeyboardMonitor(userSettings); | ||
keyboardMonitor?.Start(); | ||
} | ||
} | ||
|
||
protected override void OnExit(ExitEventArgs e) | ||
{ | ||
if (_instanceMutex != null) | ||
{ | ||
_instanceMutex.ReleaseMutex(); | ||
} | ||
|
||
base.OnExit(e); | ||
} | ||
|
||
private void Application_Exit(object sender, ExitEventArgs e) | ||
{ | ||
Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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.Windows; | ||
|
||
namespace PowerOCR.Helpers; | ||
|
||
/// <summary> | ||
/// Functions to constrain the mouse cursor (typically used when dragging) | ||
/// </summary> | ||
public static class CursorClipper | ||
{ | ||
/// <summary> | ||
/// Constrain mouse cursor to the area of the specified UI element. | ||
/// </summary> | ||
/// <param name="element">Target UI element.</param> | ||
/// <returns>True on success.</returns> | ||
public static bool ClipCursor(FrameworkElement element) | ||
{ | ||
const double dpi96 = 96.0; | ||
|
||
var topLeft = element.PointToScreen(new Point(0, 0)); | ||
|
||
PresentationSource source = PresentationSource.FromVisual(element); | ||
if (source?.CompositionTarget == null) | ||
{ | ||
return false; | ||
} | ||
|
||
double dpiX = dpi96 * source.CompositionTarget.TransformToDevice.M11; | ||
double dpiY = dpi96 * source.CompositionTarget.TransformToDevice.M22; | ||
|
||
var width = (int)((element.ActualWidth + 1) * dpiX / dpi96); | ||
var height = (int)((element.ActualHeight + 1) * dpiY / dpi96); | ||
|
||
OSInterop.RECT rect = new OSInterop.RECT | ||
{ | ||
Left = (int)topLeft.X, | ||
Top = (int)topLeft.Y, | ||
Right = (int)topLeft.X + width, | ||
Bottom = (int)topLeft.Y + height, | ||
}; | ||
|
||
return OSInterop.ClipCursor(ref rect); | ||
} | ||
|
||
/// <summary> | ||
/// Remove any mouse cursor constraint. | ||
/// </summary> | ||
/// <returns>True on success.</returns> | ||
public static bool UnClipCursor() | ||
{ | ||
return OSInterop.ClipCursor(IntPtr.Zero); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/modules/PowerOCR/PowerOCR/Helpers/IThrottledActionInvoker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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; | ||
|
||
namespace PowerOCR.Helpers; | ||
|
||
public interface IThrottledActionInvoker | ||
{ | ||
void ScheduleAction(Action action, int milliseconds); | ||
} |
Oops, something went wrong.