# Thread: Interacting with the OSRS window (without Hijack).

1. ## 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

• 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
1. 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.
Last edited by Kasi; 07-11-2018 at 12:05 PM.

2. In regards to:
I decided to port and release after seeing the RDP thread
and that comment on discord
[3:37 AM] Kasi: jeeze [3:37 AM] Kasi: rdp to send input
It seems you have a bit different thoughts about the thread, limiting it to OSRS (was it the click-bait title?)? As far as I am aware it's the best working solution anyone shared with the community. Specially when compared to the earlier normal suggestion that often floats around, which was to use a VM of sorts, then it's a huge upgrade.

Just to be clear, for anyone reading: RDP is not limited to OSRS, it's for any sort of script that would otherwise take over your mouse, keyboard, or simply require your PC to otherwise be left alone. I personally had NXT (RS3) those Android emulators, and obviously OSRS in mind when I decided to make the thread, but also knowing it would work for anything else just like that - without a hard setup process, or otherwise being very resource hungry.

Glad you shared your work. Hope to see more, preferably before I post something to drive you.
Last edited by slacky; 03-30-2018 at 12:24 AM.

3. Originally Posted by slacky
...
I just feel like it's overkill (feel the same way about VMs) in terms of resources. But yeah, if you're looking for a contained solution which supports everything, then yeah, RDP/VMs is probably the better option. Always felt like SRL was focused on learning based around botting Runescape.

BTW, this tool probably works for java rs3 too, the concept is applicable to both games (probably without any changes too). Just hasn't been tested on rs3. Regarding NXT, PostMessage/SendMessage both work on that client iirc - Without hijacking user input. IDK about the specific android emulator you're talking about, but i'm pretty sure there'll be a more direct method of sending input than to use RDP/VMs. All these solutions have a lower footprint than RDP/VMs.

4. Originally Posted by Kasi
I just feel like it's overkill (feel the same way about VMs) in terms of resources. But yeah, if you're looking for a contained solution which supports everything, then yeah, RDP/VMs is probably the better option. Always felt like SRL was focused on learning based around botting Runescape.

BTW, this tool probably works for java rs3 too, the concept is applicable to both games (probably without any changes too). Just hasn't been tested on rs3. Regarding NXT, PostMessage/SendMessage both work on that client iirc - Without hijacking user input. IDK about the specific android emulator you're talking about, but i'm pretty sure there'll be a more direct method of sending input than to use RDP/VMs. All these solutions have a lower footprint than RDP/VMs.
Just for clarity, placing RDP in the same box as a VM when talking about resource footprint is wrong. VMs are naturally heavier, no matter how fancy VM. RDP will mainly cause small a rise in mem usage.
Anyhow, sure, if someone was willing to write us them specialized solutions, then we can in fact enjoy that better solution. But that does require someone with that knowledge to step up and "just do it". I do however like the idea of using RDP (a lot more than VMs), as it does out of the box, without having to think about it give you a easy af way to bot anything.

As for them android emulators, I am not sure, don't think it should matter either, but there are some scripts using one on this forum that became quite popular, and spotted a few half-private scripts the past years.
Last edited by slacky; 03-30-2018 at 01:21 AM.

5. Originally Posted by slacky
Just for clarity, placing RDP in the same box as a VM when talking about resource footprint is wrong. VMs are naturally heavier, no matter how fancy VM. RDP will mainly cause small a rise in mem usage.
Yeah, but resource usage is def a lot higher than using any of the niche solutions i pointed out.

6. Update: Added exports for Simba.

7. SRL Junior Member
Join Date
Jul 2007
Posts
51
Mentioned
0 Post(s)
Quoted
20 Post(s)
Can anyone help me get this working, I tried the export to simba portion and had no luck with getting it setup to work.

8. Originally Posted by imalama101
Can anyone help me get this working, I tried the export to simba portion and had no luck with getting it setup to work.
I just read your pm. This won't work with a RSPS as it is. It currently only supports OSRS but it should be possible to support private server clients with modification.

As for your other questions. It works with a PID. You pass a PID to the methods. This means you can have multiple clients with one Simba. You can check how it works by reading the source along with the first post of this thread. Should be pretty straight forward to understand if you're proficient in c++.
Last edited by Kasi; 06-20-2018 at 11:40 PM.

9. SRL Junior Member
Join Date
Feb 2012
Location
Portugal
Posts
90
Mentioned
3 Post(s)
Quoted
38 Post(s)

10. Updated hosted binaries.

11. SRL Junior Member
Join Date
Jul 2007
Posts
51
Mentioned
0 Post(s)
Quoted
20 Post(s)
Can I use this with a rsps?

12. Registered User
Join Date
Jul 2018
Posts
16
Mentioned
0 Post(s)
Quoted
6 Post(s)
Originally Posted by imalama101
Can I use this with a rsps?