A few days ago I decided to make an application that can activate cheats on minecraft in an easy UI application.
(If you’re familiar with minecraft, you’ll understand how harsh spawning items can be).
So in order to execute commands inside minecraft (A game writting in Java), I had to send the keystrokes to the program.
First of all well use the User32.dll so we’ll have to import that in our project.
At the top of our project we'll have to include " using System.Runtime.InteropServices; "
this is to make DllImport(..) avaible for use.
What happens here, in short, is that our user32.dll (a standard .dll file) get’s load into our application.
Here you can already tell that the FindWindow command which we are going to use later on, is requiring 2 inputs of the type String.
Another important thing to notice is the SetForegroundWindow, as this will look familiar later on when we make a call to our applications window.
After we have our partial class set up, We create a button on the _Click event. And obviously we'll want to add some code to this, to make our button send it's keys.
Let’s explain this part of the coding a bit, as this is where our “magic” is going to happen.
IntPtr handle = FindWindow(null, “Minecraft”);
Here we use the FindWindow arguement, the EntryPoint of our .dll file, to find the window we want our application to write something in.
The first arguement I pass trough is “null”, meaning that we are only going to look at the window title.
If the window title = our string, we have succesfully found our window.
The reason why I’ve used a “null” as the first arguement, is because you can only run one minecraft application at the same time, so the window title won’t occur twice.
(due to your account only being used at one location at one specific point in time.)
So by using the SendKeys.Send(“text”) arguement we can do something like this relatively simple.
At the moment I’m making an admin-tools application for minecraft to many lives just a bit easier, and a part of it is the actual SendKeys arguement!
And credit goes where credit’s due, Bart De Smet http://community.bartdesmet.net/blogs/bart/Default.aspx) has pointed me in the right direction regarding the full application, aswell as the best way to send keystrokes to the application!