mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Fix for repeating key in Windows < 7
This commit is contained in:
parent
6a79bdda46
commit
8588fbd510
4 changed files with 56 additions and 3 deletions
|
@ -15,7 +15,7 @@ Features:
|
||||||
* Editor: a settings window for the drop shadow effect has been added.
|
* Editor: a settings window for the drop shadow effect has been added.
|
||||||
|
|
||||||
Bugs resolved:
|
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 #1610: Image editor: 'Obfuscate' and 'Highlight' and more, now should rotate / resize correctly.
|
||||||
* Bug #1619: Image editor: Autocrop now also considers the elements.
|
* Bug #1619: Image editor: Autocrop now also considers the elements.
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -27,6 +28,7 @@ using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Plugin;
|
using Greenshot.Plugin;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
|
|
||||||
namespace GreenshotPlugin.Controls {
|
namespace GreenshotPlugin.Controls {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -37,6 +39,9 @@ namespace GreenshotPlugin.Controls {
|
||||||
public class HotkeyControl : GreenshotTextBox {
|
public class HotkeyControl : GreenshotTextBox {
|
||||||
private static ILog LOG = LogManager.GetLogger(typeof(HotkeyControl));
|
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
|
// Holds the list of hotkeys
|
||||||
private static Dictionary<int, HotKeyHandler> keyHandlers = new Dictionary<int, HotKeyHandler>();
|
private static Dictionary<int, HotKeyHandler> keyHandlers = new Dictionary<int, HotKeyHandler>();
|
||||||
private static int hotKeyCounter = 1;
|
private static int hotKeyCounter = 1;
|
||||||
|
@ -474,7 +479,7 @@ namespace GreenshotPlugin.Controls {
|
||||||
modifiers |= (uint)Modifiers.WIN;
|
modifiers |= (uint)Modifiers.WIN;
|
||||||
}
|
}
|
||||||
// Disable repeating hotkey for Windows 7 and beyond, as described in #1559
|
// 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;
|
modifiers |= (uint)Modifiers.NO_REPEAT;
|
||||||
}
|
}
|
||||||
if (RegisterHotKey(hotkeyHWND, hotKeyCounter, modifiers, (uint)virtualKeyCode)) {
|
if (RegisterHotKey(hotkeyHWND, hotKeyCounter, modifiers, (uint)virtualKeyCode)) {
|
||||||
|
@ -516,7 +521,13 @@ namespace GreenshotPlugin.Controls {
|
||||||
public static bool HandleMessages(ref Message m) {
|
public static bool HandleMessages(ref Message m) {
|
||||||
if (m.Msg == WM_HOTKEY) {
|
if (m.Msg == WM_HOTKEY) {
|
||||||
// Call handler
|
// Call handler
|
||||||
keyHandlers[(int)m.WParam]();
|
if (isWindows7OrOlder) {
|
||||||
|
keyHandlers[(int)m.WParam]();
|
||||||
|
} else {
|
||||||
|
if (eventDelay.Check()) {
|
||||||
|
keyHandlers[(int)m.WParam]();
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
41
GreenshotPlugin/Core/EventDelay.cs
Normal file
41
GreenshotPlugin/Core/EventDelay.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,6 +34,7 @@
|
||||||
<Compile Include="Controls\GreenshotRadioButton.cs">
|
<Compile Include="Controls\GreenshotRadioButton.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Core\EventDelay.cs" />
|
||||||
<Compile Include="Core\FastBitmap.cs" />
|
<Compile Include="Core\FastBitmap.cs" />
|
||||||
<Compile Include="GlobalSuppressions.cs" />
|
<Compile Include="GlobalSuppressions.cs" />
|
||||||
<Compile Include="IEInterop\IHTMLBodyElement.cs" />
|
<Compile Include="IEInterop\IHTMLBodyElement.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue