Skip to content

Commit

Permalink
Fix encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Roemer committed Apr 8, 2021
1 parent d7b8475 commit 048adad
Showing 1 changed file with 59 additions and 59 deletions.
118 changes: 59 additions & 59 deletions src/FlaUInspect/Core/HoverMode.cs
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Threading;
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Input;

namespace FlaUInspect.Core
{
public class HoverMode
{
private readonly AutomationBase _automation;
private readonly DispatcherTimer _dispatcherTimer;
private AutomationElement _currentHoveredElement;

public event Action<AutomationElement> ElementHovered;

public HoverMode(AutomationBase automation)
{
_automation = automation;
_dispatcherTimer = new DispatcherTimer();
_dispatcherTimer.Tick += DispatcherTimerTick;
_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(500);
}

public void Start()
{
_currentHoveredElement = null;
_dispatcherTimer.Start();
}

public void Stop()
{
_currentHoveredElement = null;
_dispatcherTimer.Stop();
}

private void DispatcherTimerTick(object sender, EventArgs e)
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Threading;
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Input;

namespace FlaUInspect.Core
{
public class HoverMode
{
private readonly AutomationBase _automation;
private readonly DispatcherTimer _dispatcherTimer;
private AutomationElement _currentHoveredElement;

public event Action<AutomationElement> ElementHovered;

public HoverMode(AutomationBase automation)
{
_automation = automation;
_dispatcherTimer = new DispatcherTimer();
_dispatcherTimer.Tick += DispatcherTimerTick;
_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(500);
}

public void Start()
{
_currentHoveredElement = null;
_dispatcherTimer.Start();
}

public void Stop()
{
_currentHoveredElement = null;
_dispatcherTimer.Stop();
}

private void DispatcherTimerTick(object sender, EventArgs e)
{
if (System.Windows.Input.Keyboard.Modifiers.HasFlag(System.Windows.Input.ModifierKeys.Control))
{
var screenPos = Mouse.Position;
try
{
var hoveredElement = _automation.FromPoint(screenPos);
// Skip items in the current process
// Like Inspect itself or the overlay window
if (hoveredElement.Properties.ProcessId == Process.GetCurrentProcess().Id)
{
return;
}
if (!Equals(_currentHoveredElement, hoveredElement))
{
_currentHoveredElement = hoveredElement;
ElementHovered?.Invoke(hoveredElement);
}
else
{
ElementHighlighter.HighlightElement(hoveredElement);
{
var hoveredElement = _automation.FromPoint(screenPos);
// Skip items in the current process
// Like Inspect itself or the overlay window
if (hoveredElement.Properties.ProcessId == Process.GetCurrentProcess().Id)
{
return;
}
if (!Equals(_currentHoveredElement, hoveredElement))
{
_currentHoveredElement = hoveredElement;
ElementHovered?.Invoke(hoveredElement);
}
else
{
ElementHighlighter.HighlightElement(hoveredElement);
}
}
catch (UnauthorizedAccessException)
Expand All @@ -66,7 +66,7 @@ private void DispatcherTimerTick(object sender, EventArgs e)
string message = "You are accessing a protected UI element in hover mode.\nTry to start FlaUInspect as administrator.";
MessageBox.Show(message, caption, MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
}
}
}
}
}
}
}

0 comments on commit 048adad

Please sign in to comment.