Interacting with the OSRS window (without Hijack).
KInput
KInput is essentially a technique I've been sitting on for a couple years (I decided to port and release after seeing the RDP thread). It simply sends different types of events (Focus, Key, Mouse, and MouseWheel) to the OSRS Client and it does this without hijacking the system event threads. This version is a heavily modified version, ripped from AlpacaBot. The low down is that it works using JNI and you do not need hooks.
Notes
To test out the project, you can simply mess around with the Create/Delete block inside of KInputTest/main.cpp after reading the notes above.
Enjoy!
https://github.com/Kasi-R/KInput
Updates
- Added exports for Simba.
- Added support for Runelite and OSBuddy. Thanks @Patriq;
Issues & Potential Optimisations
(If anyone wants to attempt them.)
- GetRemoteProcAddress call in CallExport can be cached.
- VirtualAllocEx call in CallExport can be cached.
Setup
- Drag KInput.dll and KInputCtrl.dll to the Plugins folder in Simba (C:/Simba/Plugins/ for me).
Example
Simba Code:
program new;
{$loadlib KInputCtrl}
var
PID : Int32 = 80085;
begin
if (KInput_Create(PID)) then
begin
KInput_MouseEvent(PID, 501, KInput_CurrentTimeMS(), 0, 485, 290, 1, false, 1);
KInput_Delete(PID);
end;
end.
Useful Info
CPP Code:
typedef enum Focus_Event
{
GAINED = 1004,
LOST = 1005
} Focus_Event;
typedef enum Mouse_Event
{
NOBUTTON = 0,
BUTTON1 = 1,
BUTTON2 = 2,
BUTTON3 = 3,
MOUSE_CLICK = 500,
MOUSE_PRESS = 501,
MOUSE_RELEASE = 502,
MOUSE_MOVE = 503,
MOUSE_ENTER = 504,
MOUSE_EXIT = 505,
MOUSE_DRAG = 506,
MOUSE_WHEEL = 507
} Mouse_Event;
typedef enum Key_Event
{
KEY_TYPED = 400,
KEY_PRESSED = 401,
KEY_RELEASED = 402
} Key_Event;
This plugin offers raw events. Complete events are sent like so:
GainFocus: Focus_Event::GAIN_FOCUS
LoseFocus: Focus_Event::LOSE_FOCUS
KeyDown: Key_Event::KEY_DOWN followed by Key_Event::KEY_TYPED.
KeyUp: Key_Event::KEY_RELEASED.
MouseMove: Mouse_Event::MOUSE_MOVE
MouseDrag: Mouse_Event::MOUSE_DRAG
MouseDown: Mouse_Event::MOUSE_PRESS
MouseUp (if Dragging): Mouse_Event::MOUSE_RELEASE
MouseUp: Mouse_Event::MOUSE_RELEASE followed by Mouse_Event::MOUSE_CLICK.
MouseWheel: Mouse_Event::MOUSE_WHEEL (have to MouseMove to the correct location first)
The modifiers are essentially buttons held down like Ctrl, Shift etc.
CPP Code:
std::int32_t GetModifiers()
{
std::int32_t Result = 0;
if (IsShiftDown())
Result |= 1;
if (IsControlDown())
Result |= 2;
if (IsAltDown())
Result |= 8;
return Result;
}
You need to also handle Focus events properly. RS queries whether the client is in focus (specifically the last time it gained focus). Sending a Mouse / key event etc without focus is probably a bad thing.