screenshot plugin: Allow hotkey to be changed from insert

This commit is contained in:
Max Weber
2018-06-16 19:01:28 -06:00
parent bd99ada685
commit a42906edbe
4 changed files with 25 additions and 84 deletions

View File

@@ -37,12 +37,6 @@ import lombok.Getter;
@Getter @Getter
public class Keybind public class Keybind
{ {
public static final Keybind NOT_SET = new Keybind(KeyEvent.VK_UNDEFINED, 0);
public static final Keybind CTRL = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.CTRL_DOWN_MASK);
public static final Keybind ALT = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.ALT_DOWN_MASK);
public static final Keybind SHIFT = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.SHIFT_DOWN_MASK);
private static final BiMap<Integer, Integer> modifierToKeyCode = new ImmutableBiMap.Builder<Integer, Integer>() private static final BiMap<Integer, Integer> modifierToKeyCode = new ImmutableBiMap.Builder<Integer, Integer>()
.put(InputEvent.CTRL_DOWN_MASK, KeyEvent.VK_CONTROL) .put(InputEvent.CTRL_DOWN_MASK, KeyEvent.VK_CONTROL)
.put(InputEvent.ALT_DOWN_MASK, KeyEvent.VK_ALT) .put(InputEvent.ALT_DOWN_MASK, KeyEvent.VK_ALT)
@@ -54,6 +48,12 @@ public class Keybind
private static final int KEYBOARD_MODIFIER_MASK = modifierToKeyCode.keySet().stream() private static final int KEYBOARD_MODIFIER_MASK = modifierToKeyCode.keySet().stream()
.reduce((a, b) -> a | b).get(); .reduce((a, b) -> a | b).get();
public static final Keybind NOT_SET = new Keybind(KeyEvent.VK_UNDEFINED, 0);
public static final Keybind CTRL = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.CTRL_DOWN_MASK);
public static final Keybind ALT = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.ALT_DOWN_MASK);
public static final Keybind SHIFT = new Keybind(KeyEvent.VK_UNDEFINED, InputEvent.SHIFT_DOWN_MASK);
private final int keyCode; private final int keyCode;
private final int modifiers; private final int modifiers;

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.screenshot;
import net.runelite.client.config.Config; import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Keybind;
@ConfigGroup( @ConfigGroup(
keyName = "screenshot", keyName = "screenshot",
@@ -124,14 +125,14 @@ public interface ScreenshotConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "enableShortcut", keyName = "hotkey",
name = "Screenshot with [Insert]", name = "Screenshot hotkey",
description = "Configures whether or not screenshots can be taken with the Insert key", description = "When you press this key a screenshot will be taken",
position = 8 position = 10
) )
default boolean isScreenshotEnabled() default Keybind hotkey()
{ {
return false; return Keybind.NOT_SET;
} }
@ConfigItem( @ConfigItem(

View File

@@ -1,67 +0,0 @@
/*
* Copyright (c) 2018, Seth <http://github.com/sethtroll>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.screenshot;
import java.awt.event.KeyEvent;
import java.util.Date;
import javax.inject.Inject;
import net.runelite.client.input.KeyListener;
import static net.runelite.client.plugins.screenshot.ScreenshotPlugin.format;
public class ScreenshotInput implements KeyListener
{
private final ScreenshotConfig config;
private final ScreenshotPlugin plugin;
@Inject
ScreenshotInput(ScreenshotConfig config, ScreenshotPlugin plugin)
{
this.config = config;
this.plugin = plugin;
}
@Override
public void keyPressed(KeyEvent event)
{
}
@Override
public void keyTyped(KeyEvent event)
{
}
@Override
public void keyReleased(KeyEvent event)
{
if (!config.isScreenshotEnabled())
return;
if (event.getKeyCode() == KeyEvent.VK_INSERT)
{
plugin.takeScreenshot(format(new Date()));
}
}
}

View File

@@ -82,6 +82,7 @@ import net.runelite.client.ui.DrawManager;
import net.runelite.client.ui.NavigationButton; import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.TitleToolbar; import net.runelite.client.ui.TitleToolbar;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.HotkeyListener;
import net.runelite.client.util.Text; import net.runelite.client.util.Text;
import net.runelite.http.api.RuneLiteAPI; import net.runelite.http.api.RuneLiteAPI;
import okhttp3.Call; import okhttp3.Call;
@@ -155,9 +156,6 @@ public class ScreenshotPlugin extends Plugin
@Inject @Inject
private DrawManager drawManager; private DrawManager drawManager;
@Inject
private ScreenshotInput inputListener;
@Inject @Inject
private ScheduledExecutorService executor; private ScheduledExecutorService executor;
@@ -166,6 +164,15 @@ public class ScreenshotPlugin extends Plugin
private NavigationButton titleBarButton; private NavigationButton titleBarButton;
private final HotkeyListener hotkeyListener = new HotkeyListener(() -> config.hotkey())
{
@Override
public void hotkeyReleased()
{
takeScreenshot(format(new Date()));
}
};
@Provides @Provides
ScreenshotConfig getConfig(ConfigManager configManager) ScreenshotConfig getConfig(ConfigManager configManager)
{ {
@@ -177,7 +184,7 @@ public class ScreenshotPlugin extends Plugin
{ {
overlayManager.add(screenshotOverlay); overlayManager.add(screenshotOverlay);
SCREENSHOT_DIR.mkdirs(); SCREENSHOT_DIR.mkdirs();
keyManager.registerKeyListener(inputListener); keyManager.registerKeyListener(hotkeyListener);
try try
{ {
@@ -221,7 +228,7 @@ public class ScreenshotPlugin extends Plugin
{ {
overlayManager.remove(screenshotOverlay); overlayManager.remove(screenshotOverlay);
titleToolbar.removeNavigation(titleBarButton); titleToolbar.removeNavigation(titleBarButton);
keyManager.unregisterKeyListener(inputListener); keyManager.unregisterKeyListener(hotkeyListener);
} }
@Subscribe @Subscribe