diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java index c6a92b11a1..77a0d98a04 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotConfig.java @@ -111,4 +111,15 @@ public interface ScreenshotConfig extends Config { return false; } + + @ConfigItem( + keyName = "enableShortcut", + name = "Screenshot with [Insert]", + description = "Configures whether or not screenshots can be taken with the Insert key", + position = 7 + ) + default boolean isScreenshotEnabled() + { + return false; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotInput.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotInput.java new file mode 100644 index 0000000000..3d6554e4fa --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotInput.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018, Seth + * 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.TIME_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(TIME_FORMAT.format(new Date()), config.displayDate()); + } + } + +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java index f0e6e02848..9e4efb9543 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/screenshot/ScreenshotPlugin.java @@ -72,6 +72,7 @@ import static net.runelite.api.widgets.WidgetInfo.TO_GROUP; import net.runelite.client.Notifier; import static net.runelite.client.RuneLite.SCREENSHOT_DIR; import net.runelite.client.config.ConfigManager; +import net.runelite.client.input.KeyManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.screenshot.imgur.ImageUploadRequest; @@ -102,7 +103,7 @@ public class ScreenshotPlugin extends Plugin private static final MediaType JSON = MediaType.parse("application/json"); private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MMM. dd, yyyy", Locale.US); - private static final DateFormat TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US); + static final DateFormat TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US); private static final Pattern NUMBER_PATTERN = Pattern.compile("([0-9]+)"); private static final Pattern LEVEL_UP_PATTERN = Pattern.compile("Your ([a-zA-Z]+) (?:level is|are)? now (\\d+)\\."); @@ -132,9 +133,15 @@ public class ScreenshotPlugin extends Plugin @Inject private OverlayRenderer overlayRenderer; + @Inject + private ScreenshotInput inputListener; + @Inject private ScheduledExecutorService executor; + @Inject + private KeyManager keyManager; + private NavigationButton titleBarButton; @Provides @@ -147,6 +154,7 @@ public class ScreenshotPlugin extends Plugin protected void startUp() throws Exception { SCREENSHOT_DIR.mkdirs(); + keyManager.registerKeyListener(inputListener); try { @@ -191,6 +199,7 @@ public class ScreenshotPlugin extends Plugin protected void shutDown() throws Exception { titleToolbar.removeNavigation(titleBarButton); + keyManager.unregisterKeyListener(inputListener); } @Subscribe @@ -387,7 +396,7 @@ public class ScreenshotPlugin extends Plugin * @param fileName Filename to use, without file extension. * @param displayDate Whether to show today's date on the report button as the screenshot is taken. */ - private void takeScreenshot(String fileName, boolean displayDate) + void takeScreenshot(String fileName, boolean displayDate) { if (client.getGameState() == GameState.LOGIN_SCREEN) {