Add support for intercepting mouse and keyboard input

Also allow translating mouse input for stretched fixed mode.

This is required for moving overlays, and interacting with the instance map.
This commit is contained in:
Adam
2018-02-27 19:23:08 -05:00
parent 326f498ae9
commit a999863a80
13 changed files with 801 additions and 0 deletions

View File

@@ -25,6 +25,9 @@
package net.runelite.client.callback;
import com.google.common.eventbus.EventBus;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import org.slf4j.Logger;
/**
@@ -37,4 +40,59 @@ public class Hooks
public static Logger log;
public static EventBus eventBus;
public static MouseEvent mousePressed(MouseEvent mouseEvent)
{
throw new RuntimeException();
}
public static MouseEvent mouseReleased(MouseEvent mouseEvent)
{
throw new RuntimeException();
}
public static MouseEvent mouseClicked(MouseEvent mouseEvent)
{
throw new RuntimeException();
}
public static MouseEvent mouseEntered(MouseEvent mouseEvent)
{
throw new RuntimeException();
}
public static MouseEvent mouseExited(MouseEvent mouseEvent)
{
throw new RuntimeException();
}
public static MouseEvent mouseDragged(MouseEvent mouseEvent)
{
throw new RuntimeException();
}
public static MouseEvent mouseMoved(MouseEvent mouseEvent)
{
throw new RuntimeException();
}
public static void mouseWheelMoved(MouseWheelEvent event)
{
throw new RuntimeException();
}
public static void keyPressed(KeyEvent keyEvent)
{
throw new RuntimeException();
}
public static void keyReleased(KeyEvent keyEvent)
{
throw new RuntimeException();
}
public static void keyTyped(KeyEvent keyEvent)
{
throw new RuntimeException();
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.mixins;
import java.awt.event.KeyEvent;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Replace;
import net.runelite.client.callback.Hooks;
import net.runelite.rs.api.RSKeyFocusListener;
@Mixin(RSKeyFocusListener.class)
public abstract class RSKeyFocusListenerMixin implements RSKeyFocusListener
{
@Copy("keyPressed")
abstract void rs$keyPressed(KeyEvent keyEvent);
@Copy("keyReleased")
abstract void rs$keyReleased(KeyEvent keyEvent);
@Copy("keyTyped")
abstract void rs$keyTyped(KeyEvent keyEvent);
@Override
@Replace("keyPressed")
public final synchronized void keyPressed(KeyEvent keyEvent)
{
Hooks.keyPressed(keyEvent);
if (!keyEvent.isConsumed())
{
rs$keyPressed(keyEvent);
}
}
@Override
@Replace("keyReleased")
public final synchronized void keyReleased(KeyEvent keyEvent)
{
Hooks.keyReleased(keyEvent);
if (!keyEvent.isConsumed())
{
rs$keyReleased(keyEvent);
}
}
@Override
@Replace("keyTyped")
public final void keyTyped(KeyEvent keyEvent)
{
Hooks.keyTyped(keyEvent);
if (!keyEvent.isConsumed())
{
rs$keyTyped(keyEvent);
}
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.mixins;
import java.awt.event.MouseEvent;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Replace;
import net.runelite.client.callback.Hooks;
import net.runelite.rs.api.RSMouseInput;
@Mixin(RSMouseInput.class)
public abstract class RSMouseInputMixin implements RSMouseInput
{
@Copy("mousePressed")
abstract void rs$mousePressed(MouseEvent mouseEvent);
@Copy("mouseReleased")
abstract void rs$mouseReleased(MouseEvent mouseEvent);
@Copy("mouseClicked")
abstract void rs$mouseClicked(MouseEvent mouseEvent);
@Copy("mouseEntered")
abstract void rs$mouseEntered(MouseEvent mouseEvent);
@Copy("mouseExited")
abstract void rs$mouseExited(MouseEvent mouseEvent);
@Copy("mouseDragged")
abstract void rs$mouseDragged(MouseEvent mouseEvent);
@Copy("mouseMoved")
abstract void rs$mouseMoved(MouseEvent mouseEvent);
@Override
@Replace("mousePressed")
public synchronized void mousePressed(MouseEvent mouseEvent)
{
mouseEvent = Hooks.mousePressed(mouseEvent);
if (!mouseEvent.isConsumed())
{
rs$mousePressed(mouseEvent);
}
}
@Override
@Replace("mouseReleased")
public synchronized void mouseReleased(MouseEvent mouseEvent)
{
mouseEvent = Hooks.mouseReleased(mouseEvent);
if (!mouseEvent.isConsumed())
{
rs$mouseReleased(mouseEvent);
}
}
@Override
@Replace("mouseClicked")
public void mouseClicked(MouseEvent event)
{
event = Hooks.mouseClicked(event);
if (!event.isConsumed())
{
rs$mouseClicked(event);
}
}
@Override
@Replace("mouseEntered")
public synchronized void mouseEntered(MouseEvent mouseEvent)
{
mouseEvent = Hooks.mouseEntered(mouseEvent);
if (!mouseEvent.isConsumed())
{
rs$mouseEntered(mouseEvent);
}
}
@Override
@Replace("mouseExited")
public synchronized void mouseExited(MouseEvent mouseEvent)
{
mouseEvent = Hooks.mouseExited(mouseEvent);
if (!mouseEvent.isConsumed())
{
rs$mouseExited(mouseEvent);
}
}
@Override
@Replace("mouseDragged")
public synchronized void mouseDragged(MouseEvent mouseEvent)
{
mouseEvent = Hooks.mouseDragged(mouseEvent);
if (!mouseEvent.isConsumed())
{
rs$mouseDragged(mouseEvent);
}
}
@Override
@Replace("mouseMoved")
public synchronized void mouseMoved(MouseEvent mouseEvent)
{
mouseEvent = Hooks.mouseMoved(mouseEvent);
if (!mouseEvent.isConsumed())
{
rs$mouseMoved(mouseEvent);
}
}
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.mixins;
import java.awt.event.MouseWheelEvent;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Replace;
import net.runelite.client.callback.Hooks;
import net.runelite.rs.api.RSMouseWheelHandler;
@Mixin(RSMouseWheelHandler.class)
public abstract class RSMouseWheelHandlerMixin implements RSMouseWheelHandler
{
@Copy("mouseWheelMoved")
abstract void rs$mouseWheelMoved(MouseWheelEvent event);
@Override
@Replace("mouseWheelMoved")
public void mouseWheelMoved(MouseWheelEvent event)
{
Hooks.mouseWheelMoved(event);
if (!event.isConsumed())
{
rs$mouseWheelMoved(event);
}
}
}