I am trying to send keyboard inputs to Minecraft to move the player, however when I try using SendKeys.SendWait("W");
nothing happens. If I open the chat in Minecraft it types "W" in chat, however outside of chat my inputs seem to be ignored. Thanks.
Edit: I have tried using SendInput
as well as InputSimulator
both having the same effect.
Basically Windows has three protection ring. By doing SendKeys
you are sending a ring 3 command to the application. However DirectX only listens to ring 0 and ring 1 (possibly ring 2) commands to reduce the fraction delay caused by command passing through a driver to application.
So in order to make DirectX games react to the event you sent you must send it at driver level. You can simulate a ring 2 driver input by pinvoke WINDOWS api SendInput with scan code (don't use virtual code).
If scan code doesn't work then the game might be blocking ring 2 commands for anti-hacking purpose. In that case you would need to write a driver + a virtual hardware to send ring 1 commands directly. (do not try this if you are not experienced. a Blue screen of death or even corrupted system may result if a mistake is made)
I solved it by using InputSimulatorPlus
https://github.com/TChatzigiannakis/InputSimulatorPlus
InputSimulator s = new InputSimulator();
s.Keyboard.KeyDown(VirtualKeyCode.VK_W);
this just runs forward, to stop use s.Keyboard.KeyUp(VirtualKeyCode.VK_W);
you can also use s.Keyboard.KeyPress(VirtualKeyCode.VK_W);
and this will just click the "W" key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With