diff --git a/Greenshot/releases/additional_files/readme.txt.template b/Greenshot/releases/additional_files/readme.txt.template index a903da6bf..469c391ea 100644 --- a/Greenshot/releases/additional_files/readme.txt.template +++ b/Greenshot/releases/additional_files/readme.txt.template @@ -15,7 +15,7 @@ Features: * Editor: a settings window for the drop shadow effect has been added. Bugs resolved: -* Bug #1559,#1643: Repeating hotkeys are now prevented, unfortunately only for Windows 7 and later. +* Bug #1559,#1643: Repeating hotkeys are now prevented. * Bug #1610: Image editor: 'Obfuscate' and 'Highlight' and more, now should rotate / resize correctly. * Bug #1619: Image editor: Autocrop now also considers the elements. diff --git a/GreenshotPlugin/Controls/HotkeyControl.cs b/GreenshotPlugin/Controls/HotkeyControl.cs index 00731f9e0..122f58c29 100644 --- a/GreenshotPlugin/Controls/HotkeyControl.cs +++ b/GreenshotPlugin/Controls/HotkeyControl.cs @@ -18,6 +18,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + using System; using System.Collections; using System.Collections.Generic; @@ -27,6 +28,7 @@ using System.Windows.Forms; using Greenshot.Plugin; using log4net; +using GreenshotPlugin.Core; namespace GreenshotPlugin.Controls { /// @@ -37,6 +39,9 @@ namespace GreenshotPlugin.Controls { public class HotkeyControl : GreenshotTextBox { private static ILog LOG = LogManager.GetLogger(typeof(HotkeyControl)); + private static EventDelay eventDelay = new EventDelay(TimeSpan.FromMilliseconds(600).Ticks); + private static bool isWindows7OrOlder = Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1; + // Holds the list of hotkeys private static Dictionary keyHandlers = new Dictionary(); private static int hotKeyCounter = 1; @@ -474,7 +479,7 @@ namespace GreenshotPlugin.Controls { modifiers |= (uint)Modifiers.WIN; } // Disable repeating hotkey for Windows 7 and beyond, as described in #1559 - if (Environment.OSVersion.Version.Major >= 6 && Environment.OSVersion.Version.Minor >= 1) { + if (isWindows7OrOlder) { modifiers |= (uint)Modifiers.NO_REPEAT; } if (RegisterHotKey(hotkeyHWND, hotKeyCounter, modifiers, (uint)virtualKeyCode)) { @@ -516,7 +521,13 @@ namespace GreenshotPlugin.Controls { public static bool HandleMessages(ref Message m) { if (m.Msg == WM_HOTKEY) { // Call handler - keyHandlers[(int)m.WParam](); + if (isWindows7OrOlder) { + keyHandlers[(int)m.WParam](); + } else { + if (eventDelay.Check()) { + keyHandlers[(int)m.WParam](); + } + } return true; } return false; diff --git a/GreenshotPlugin/Core/EventDelay.cs b/GreenshotPlugin/Core/EventDelay.cs new file mode 100644 index 000000000..4e6193965 --- /dev/null +++ b/GreenshotPlugin/Core/EventDelay.cs @@ -0,0 +1,41 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2014 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; + +namespace GreenshotPlugin.Core { + public class EventDelay { + private long lastCheck = 0; + private long waitTime; + public EventDelay(long ticks) { + this.waitTime = ticks; + } + + public bool Check() { + lock (this) { + long now = DateTime.Now.Ticks; + bool isPassed = now - lastCheck > waitTime; + lastCheck = now; + return isPassed; + } + } + } +} diff --git a/GreenshotPlugin/GreenshotPlugin.csproj b/GreenshotPlugin/GreenshotPlugin.csproj index c1bb819dc..b7fd9549c 100644 --- a/GreenshotPlugin/GreenshotPlugin.csproj +++ b/GreenshotPlugin/GreenshotPlugin.csproj @@ -34,6 +34,7 @@ Component +