diff --git a/runelite-api/src/main/java/net/runelite/api/KeyFocusListener.java b/runelite-api/src/main/java/net/runelite/api/KeyFocusListener.java new file mode 100644 index 0000000000..648232faf0 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/KeyFocusListener.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018 Charlie Waters + * 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.api; + +public interface KeyFocusListener +{ +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/FocusChanged.java b/runelite-api/src/main/java/net/runelite/api/events/FocusChanged.java new file mode 100644 index 0000000000..242823da2f --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/FocusChanged.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018 Charlie Waters + * 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.api.events; + +import lombok.Data; + +@Data +public class FocusChanged +{ + private boolean focused; +} diff --git a/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java index cd07d1ef05..f1e669caaf 100644 --- a/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java +++ b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java @@ -30,6 +30,7 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; +import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; @@ -37,6 +38,7 @@ import java.awt.image.BufferedImage; import net.runelite.api.Actor; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; +import net.runelite.api.KeyFocusListener; import net.runelite.api.MainBufferProvider; import net.runelite.api.MenuAction; import net.runelite.api.MessageNode; @@ -49,6 +51,7 @@ import net.runelite.api.WorldMapManager; import net.runelite.api.coords.LocalPoint; import net.runelite.api.events.ActorDeath; import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.FocusChanged; import net.runelite.api.events.GameTick; import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.ProjectileMoved; @@ -205,6 +208,22 @@ public class Hooks keyManager.processKeyTyped(keyEvent); } + public static void focusGained(KeyFocusListener l, FocusEvent focusEvent) + { + FocusChanged focusChanged = new FocusChanged(); + focusChanged.setFocused(true); + + eventBus.post(focusChanged); + } + + public static void focusLost(KeyFocusListener l, FocusEvent focusEvent) + { + FocusChanged focusChanged = new FocusChanged(); + focusChanged.setFocused(false); + + eventBus.post(focusChanged); + } + public static void draw(MainBufferProvider mainBufferProvider, Graphics graphics, int x, int y) { if (graphics == null) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java index 1017c3cb68..f07d27c27d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java @@ -53,6 +53,7 @@ import net.runelite.api.Node; import net.runelite.api.Region; import net.runelite.api.Tile; import net.runelite.api.events.ConfigChanged; +import net.runelite.api.events.FocusChanged; import net.runelite.api.events.MenuEntryAdded; import net.runelite.client.config.ConfigManager; import net.runelite.client.game.ItemManager; @@ -286,4 +287,13 @@ public class GroundItemsPlugin extends Plugin { return TRUE.equals(hiddenItems.getUnchecked(item)); } + + @Subscribe + public void onFocusChanged(FocusChanged focusChanged) + { + if (!focusChanged.isFocused()) + { + setHotKeyPressed(false); + } + } } diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSGameEngine.java b/runescape-api/src/main/java/net/runelite/rs/api/RSGameEngine.java index e1b6ef1f3d..e1f496943f 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSGameEngine.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSGameEngine.java @@ -25,9 +25,10 @@ package net.runelite.rs.api; import java.awt.Canvas; +import net.runelite.api.KeyFocusListener; import net.runelite.mapping.Import; -public interface RSGameEngine +public interface RSGameEngine extends KeyFocusListener { @Import("canvas") Canvas getCanvas(); diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSKeyFocusListener.java b/runescape-api/src/main/java/net/runelite/rs/api/RSKeyFocusListener.java index ea7dff369f..9ef296251b 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSKeyFocusListener.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSKeyFocusListener.java @@ -26,7 +26,8 @@ package net.runelite.rs.api; import java.awt.event.FocusListener; import java.awt.event.KeyListener; +import net.runelite.api.KeyFocusListener; -public interface RSKeyFocusListener extends KeyListener, FocusListener +public interface RSKeyFocusListener extends KeyListener, FocusListener, KeyFocusListener { }