diff --git a/streamdeck-magnifier/streamdeck-magnifier/Magnifier.cs b/streamdeck-magnifier/streamdeck-magnifier/Magnifier.cs index 51147dc..c57148c 100644 --- a/streamdeck-magnifier/streamdeck-magnifier/Magnifier.cs +++ b/streamdeck-magnifier/streamdeck-magnifier/Magnifier.cs @@ -4,6 +4,7 @@ using System; using System.Threading.Tasks; using System.Drawing; +using System.Timers; namespace Magnifier { @@ -11,7 +12,7 @@ namespace Magnifier public class Magnifier : PluginBase { private readonly MagnifierSettings settings; - private bool isRunning; + private readonly Timer Timer; private bool isFixed; private Point mouseLocation; private DateTime dateTime; @@ -21,16 +22,40 @@ public Magnifier(SDConnection connection, InitialPayload payload) : base(connect settings = payload.Settings == null || payload.Settings.Count == 0 ? MagnifierSettings.CreateDefaultSettings() : payload.Settings.ToObject(); + + Timer = new Timer(10); + Timer.Elapsed += new ElapsedEventHandler(UpdateKey); + Timer.Enabled = false; + Timer.Start(); + } + + private void UpdateKey(object sender, ElapsedEventArgs e) + { + if (Timer.Enabled) + { + var location = isFixed ? mouseLocation : ScreenHelper.GetMouseLocation(); + var img = ImageHelper.CopyFromScreen(settings.ZoomLevel, location); + img = ImageHelper.ResizeImage(img, 144, 144); + + if (settings.UseCrosshair) + { + ImageHelper.DrawCrosshair(img); + } + + Connection.SetImageAsync(img); + } } public override void Dispose() { + Timer.Stop(); + Timer.Dispose(); Logger.Instance.LogMessage(TracingLevel.INFO, $"Destructor called"); } public override void KeyPressed(KeyPayload payload) { - isRunning = !isRunning; + Timer.Enabled = !Timer.Enabled; dateTime = DateTime.Now; } @@ -39,27 +64,12 @@ public override void KeyReleased(KeyPayload payload) if ((DateTime.Now - dateTime).TotalSeconds > 2) { mouseLocation = ScreenHelper.GetMouseLocation(); - isFixed = true; - isRunning = true; + isFixed = !isFixed; + Timer.Enabled = true; } } - public override void OnTick() - { - if (isRunning) - { - var location = isFixed ? mouseLocation : ScreenHelper.GetMouseLocation(); - var img = ImageHelper.CopyFromScreen(settings.ZoomLevel, location); - img = ImageHelper.ResizeImage(img, 144, 144); - - if (settings.UseCrosshair) - { - ImageHelper.DrawCrosshair(img); - } - - Connection.SetImageAsync(img); - } - } + public override void OnTick() { } public override void ReceivedSettings(ReceivedSettingsPayload payload) { diff --git a/streamdeck-magnifier/streamdeck-magnifier/manifest.json b/streamdeck-magnifier/streamdeck-magnifier/manifest.json index 1cd5bac..ef8c8cf 100644 --- a/streamdeck-magnifier/streamdeck-magnifier/manifest.json +++ b/streamdeck-magnifier/streamdeck-magnifier/manifest.json @@ -36,7 +36,7 @@ "Description": "Converts a Stream Deck key into a screen magnifier, with up to 32x zoom.\nIncludes an option to move the mouse pixel by pixel for better precision.", "Icon": "Images/magnifierIcon", "URL": "https://github.com/VictorGrycuk/streamdeck-magnifier", - "Version": "1.2", + "Version": "1.2.1", "CodePath": "streamdeck-magnifier", "Category": "Magnifier", "CategoryIcon": "Images/categoryIcon",