Fix for repeating key in Windows < 7

This commit is contained in:
RKrom 2014-06-17 11:50:13 +02:00
commit 8588fbd510
4 changed files with 56 additions and 3 deletions

View file

@ -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.

View file

@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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 {
/// <summary>
@ -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<int, HotKeyHandler> keyHandlers = new Dictionary<int, HotKeyHandler>();
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;

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}
}
}

View file

@ -34,6 +34,7 @@
<Compile Include="Controls\GreenshotRadioButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Core\EventDelay.cs" />
<Compile Include="Core\FastBitmap.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="IEInterop\IHTMLBodyElement.cs" />