From c5905e2424b8186f28264fa34ef960b3b34aad79 Mon Sep 17 00:00:00 2001 From: sa- Date: Sat, 23 May 2020 16:52:18 +0200 Subject: [PATCH] remove keyboard shortcut --- README.md | 3 - grayzen/ColorTransformation/Grayscaler.cs | 10 +- grayzen/HotkeyHandling/HotkeyModifierKeys.cs | 16 --- grayzen/HotkeyHandling/KeyPressedEventArgs.cs | 21 ---- grayzen/HotkeyHandling/KeyboardHook.cs | 113 ------------------ grayzen/Program.cs | 4 +- grayzen/Properties/AssemblyInfo.cs | 1 - grayzen/State/AppState.cs | 32 +---- grayzen/State/State.cs | 8 +- grayzen/State/TimedColorSession.cs | 13 +- grayzen/TrayApplicationContext.cs | 7 +- grayzen/grayzen.csproj | 3 - 12 files changed, 15 insertions(+), 216 deletions(-) delete mode 100644 grayzen/HotkeyHandling/HotkeyModifierKeys.cs delete mode 100644 grayzen/HotkeyHandling/KeyPressedEventArgs.cs delete mode 100644 grayzen/HotkeyHandling/KeyboardHook.cs diff --git a/README.md b/README.md index 501a041..39aa0c7 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,3 @@ Grayscaling helps you cut down on screen time by making your computer screen les ## Instructions Download it from [releases](https://github.com/sa-/grayzen/releases) and open the file. Look for the grey circle in your Tray. - -### Timed Color Session -Press Ctrl + Alt + Space to start a Colour Session for 1 minute. diff --git a/grayzen/ColorTransformation/Grayscaler.cs b/grayzen/ColorTransformation/Grayscaler.cs index 4ff67e1..21253cc 100644 --- a/grayzen/ColorTransformation/Grayscaler.cs +++ b/grayzen/ColorTransformation/Grayscaler.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace grayzen +namespace grayzen { using static NativeMethods; @@ -28,7 +22,7 @@ internal static void GoGrey() }; MagSetFullscreenColorEffect(ref magEffectInvert); - + } internal static void DontTransformColor() diff --git a/grayzen/HotkeyHandling/HotkeyModifierKeys.cs b/grayzen/HotkeyHandling/HotkeyModifierKeys.cs deleted file mode 100644 index 13c0673..0000000 --- a/grayzen/HotkeyHandling/HotkeyModifierKeys.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace grayzen.HotkeyHandling -{ - /// - /// The enumeration of possible modifiers. - /// - [Flags] - public enum HotkeyModifierKeys : uint - { - Alt = 1, - Control = 2, - Shift = 4, - Win = 8 - } -} diff --git a/grayzen/HotkeyHandling/KeyPressedEventArgs.cs b/grayzen/HotkeyHandling/KeyPressedEventArgs.cs deleted file mode 100644 index 1a69e13..0000000 --- a/grayzen/HotkeyHandling/KeyPressedEventArgs.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Windows.Forms; - -namespace grayzen.HotkeyHandling -{ - /// - /// Event Args for the event that is fired after the hot key has been pressed. - /// - public class KeyPressedEventArgs : EventArgs - { - internal KeyPressedEventArgs(HotkeyModifierKeys modifier, Keys key) - { - Modifier = modifier; - Key = key; - } - - public HotkeyModifierKeys Modifier { get; } - - public Keys Key { get; } - } -} diff --git a/grayzen/HotkeyHandling/KeyboardHook.cs b/grayzen/HotkeyHandling/KeyboardHook.cs deleted file mode 100644 index 3957593..0000000 --- a/grayzen/HotkeyHandling/KeyboardHook.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace grayzen.HotkeyHandling -{ - public sealed class KeyboardHook : IDisposable - { - // Registers a hot key with Windows. - [DllImport("user32.dll")] - private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk); - // Unregisters the hot key with Windows. - [DllImport("user32.dll")] - private static extern bool UnregisterHotKey(IntPtr hWnd, int id); - - /// - /// Represents the window that is used internally to get the messages. - /// - private class Window : NativeWindow, IDisposable - { - private static int WM_HOTKEY = 0x0312; - public event EventHandler KeyPressed; - - public Window() - { - // create the handle for the window. - this.CreateHandle(new CreateParams()); - } - - /// - /// Overridden to get the notifications. - /// - /// - protected override void WndProc(ref Message m) - { - base.WndProc(ref m); - - // check if we got a hot key pressed. - if (m.Msg == WM_HOTKEY) - { - // get the keys. - Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); - HotkeyModifierKeys modifier = (HotkeyModifierKeys)((int)m.LParam & 0xFFFF); - - // invoke the event to notify the parent. - KeyPressed?.Invoke(this, new KeyPressedEventArgs(modifier, key)); - } - } - - - #region IDisposable Members - - public void Dispose() - { - this.DestroyHandle(); - } - - #endregion - } - - private Window _window = new Window(); - private int _currentId; - - public KeyboardHook() - { - // register the event of the inner native window. - _window.KeyPressed += delegate (object sender, KeyPressedEventArgs args) - { - KeyPressed?.Invoke(this, args); - }; - } - - /// - /// Registers a hot key in the system. - /// - /// The modifiers that are associated with the hot key. - /// The key itself that is associated with the hot key. - public void RegisterHotKey(HotkeyModifierKeys modifier, Keys key) - { - // increment the counter. - _currentId += 1; - - // register the hot key. - if (!RegisterHotKey(_window.Handle, _currentId, (uint)modifier, (uint)key)) - throw new InvalidOperationException("Couldn’t register the hot key."); - } - - /// - /// A hot key has been pressed. - /// - public event EventHandler KeyPressed; - - #region IDisposable Members - - public void Dispose() - { - // unregister all the registered hot keys. - for (int i = _currentId; i > 0; i--) - { - UnregisterHotKey(_window.Handle, i); - } - - // dispose the inner native window. - _window.Dispose(); - } - - #endregion - } -} diff --git a/grayzen/Program.cs b/grayzen/Program.cs index bf31154..de2e8fa 100644 --- a/grayzen/Program.cs +++ b/grayzen/Program.cs @@ -3,8 +3,6 @@ namespace grayzen { - using static NativeMethods; - static class Program { /// @@ -22,5 +20,5 @@ static void Main() } - + } diff --git a/grayzen/Properties/AssemblyInfo.cs b/grayzen/Properties/AssemblyInfo.cs index c270d35..6d7bace 100644 --- a/grayzen/Properties/AssemblyInfo.cs +++ b/grayzen/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/grayzen/State/AppState.cs b/grayzen/State/AppState.cs index fa0c699..b594ffa 100644 --- a/grayzen/State/AppState.cs +++ b/grayzen/State/AppState.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Timers; -using System.Threading.Tasks; -using grayzen.HotkeyHandling; -using System.Windows.Forms; - -namespace grayzen.State +namespace grayzen.State { using static NativeMethods; @@ -18,26 +9,9 @@ internal class AppState internal static void InitApp() { MagInitialize(); - SetKeyboardShortcut(); GoGrey(); } - private static void SetKeyboardShortcut() - { - KeyboardHook hook = new KeyboardHook(); - // register the event that is fired after the key press. - hook.KeyPressed += - new EventHandler(hook_KeyPressed); - - hook.RegisterHotKey(HotkeyModifierKeys.Control | HotkeyModifierKeys.Alt, - Keys.Space); - - void hook_KeyPressed(object sender, KeyPressedEventArgs e) - { - ToggleTimedColourSession(5_000); - } - } - static void ChangeState(State state) { AppState.state = state; @@ -53,12 +27,12 @@ internal static void ToggleBetweenGrayAndColour() internal static void ToggleTimedColourSession(int milliseconds) { TimedColorSession.ToggleTimedColourSession(milliseconds); - + } static void RenderState() { - if(state == State.Gray) + if (state == State.Gray) { Grayscaler.GoGrey(); } diff --git a/grayzen/State/State.cs b/grayzen/State/State.cs index a81bf34..c228a4e 100644 --- a/grayzen/State/State.cs +++ b/grayzen/State/State.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace grayzen.State +namespace grayzen.State { enum State { diff --git a/grayzen/State/TimedColorSession.cs b/grayzen/State/TimedColorSession.cs index 6f06ced..32473c7 100644 --- a/grayzen/State/TimedColorSession.cs +++ b/grayzen/State/TimedColorSession.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace grayzen.State { @@ -12,7 +8,8 @@ class TimedColorSession private static void StartTimedColourSession(int milliseconds) { - if(timer != null ) { + if (timer != null) + { timer.Dispose(); } timer = new System.Windows.Forms.Timer(); @@ -36,14 +33,14 @@ public static void ToggleTimedColourSession(int milliseconds) public static bool IsRunning() { - return - timer != null && + return + timer != null && timer.Enabled; } public static void EndTimerEarly() { - if(timer == null) { return; } + if (timer == null) { return; } timer.Dispose(); AppState.GoGrey(); } diff --git a/grayzen/TrayApplicationContext.cs b/grayzen/TrayApplicationContext.cs index 25d67f9..48f67dd 100644 --- a/grayzen/TrayApplicationContext.cs +++ b/grayzen/TrayApplicationContext.cs @@ -1,11 +1,10 @@ -using grayzen.HotkeyHandling; -using grayzen.State; +using grayzen.State; using System; using System.Windows.Forms; namespace grayzen { - + public class TrayApplicationContext : ApplicationContext { @@ -14,7 +13,7 @@ public class TrayApplicationContext : ApplicationContext public TrayApplicationContext() { // Initialize Tray Icon - MenuItem menuItem = new MenuItem("Disable for one minute", DisableForOneMinute); + MenuItem menuItem = new MenuItem("60s colour session (click again to disable)", DisableForOneMinute); trayIcon = new NotifyIcon() { Icon = Properties.Resources.grayzen, diff --git a/grayzen/grayzen.csproj b/grayzen/grayzen.csproj index 1126c76..7821751 100644 --- a/grayzen/grayzen.csproj +++ b/grayzen/grayzen.csproj @@ -50,9 +50,6 @@ - - -