Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.14.4]Simulate mouse and keyboard input
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 2
ATomo9_CY

[1.14.4]Simulate mouse and keyboard input

By ATomo9_CY, December 27, 2019 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

ATomo9_CY    0

ATomo9_CY

ATomo9_CY    0

  • Tree Puncher
  • ATomo9_CY
  • Members
  • 0
  • 10 posts
Posted December 27, 2019

Im trying to write a neural network mod that produces its own game input to play the game.

I cant figure out how to make the game use the input i produce in my mod and ignore mouse and keyboard input so i can run multiple clients and be able to do other things while it plays.

  • Quote

Share this post


Link to post
Share on other sites

cookiedragon234    6

cookiedragon234

cookiedragon234    6

  • Tree Puncher
  • cookiedragon234
  • Members
  • 6
  • 38 posts
Posted December 28, 2019
KeyBinding.setKeyBindState(mc.gameSettings.keyBind[whatever].getKeyCode(), true);

 

  • Quote

Share this post


Link to post
Share on other sites

ATomo9_CY    0

ATomo9_CY

ATomo9_CY    0

  • Tree Puncher
  • ATomo9_CY
  • Members
  • 0
  • 10 posts
Posted December 28, 2019
24 minutes ago, cookiedragon234 said:

KeyBinding.setKeyBindState(mc.gameSettings.keyBind[whatever].getKeyCode(), true);

 

Is this only for keyboard input?Also if i execute this every tick will user input be ignored?

  • Quote

Share this post


Link to post
Share on other sites

cookiedragon234    6

cookiedragon234

cookiedragon234    6

  • Tree Puncher
  • cookiedragon234
  • Members
  • 6
  • 38 posts
Posted December 28, 2019

@ATomo9_CY yes, it will override the user's input. Im not 100% sure about mouse input, but you can use stuff like mc.player.swingArm() for that

  • Quote

Share this post


Link to post
Share on other sites

ATomo9_CY    0

ATomo9_CY

ATomo9_CY    0

  • Tree Puncher
  • ATomo9_CY
  • Members
  • 0
  • 10 posts
Posted December 28, 2019 (edited)

That line of code works very well for simulating keyboard input.

I tried using it with keyBindUseItem and keyBindAttack to try to simulate mouse clicks but it didnt work.I used mc.player.swingArm(mc.player.getActiveHand()); but the game crashes because getActiveHand() returns null.There is also the problem of moving the players camera around that i haven't figured out how to do yet.

Edit:keyBindUseItem and keyBindAttack actually do work but for some reason i have to click first once manually before they start to effect the game.

Edited December 28, 2019 by ATomo9_CY
  • Quote

Share this post


Link to post
Share on other sites

ATomo9_CY    0

ATomo9_CY

ATomo9_CY    0

  • Tree Puncher
  • ATomo9_CY
  • Members
  • 0
  • 10 posts
Posted December 28, 2019 (edited)

@SubscribeEvent
public static void EntityViewRenderEvent(CameraSetup event){
    event.setYaw(yaw);
    event.setPitch(pitch);
    event.setRoll(roll);
}

 

The above code takes yaw pitch and roll as inputs to determine the position of the camera.

i think ill still need some code to determine how the user will interact with guis since it has to be done without the mouse pointer.Ill be trying to do that but if anybody has some info that could help me please do share it.

 

Edit:The code above it seems is not very usefull for what im trying to do since it just moves the camera independendly of mouse input while everything else functions based on user mouse input.

Edited December 28, 2019 by ATomo9_CY
  • Quote

Share this post


Link to post
Share on other sites

ATomo9_CY    0

ATomo9_CY

ATomo9_CY    0

  • Tree Puncher
  • ATomo9_CY
  • Members
  • 0
  • 10 posts
Posted December 28, 2019

 the code below is in MouseHelper

 public void registerCallbacks(long handle) {
      InputMappings.func_216503_a(handle, this::cursorPosCallback, this::mouseButtonCallback, this::scrollCallback);
   }

 

the methods it mentions are all private but i think they are the ones responsible for determining the mouse position and actions ingame.

Is there a way to call those methods or fake a mouse movement to get them called?

 

 

  • Quote

Share this post


Link to post
Share on other sites

ATomo9_CY    0

ATomo9_CY

ATomo9_CY    0

  • Tree Puncher
  • ATomo9_CY
  • Members
  • 0
  • 10 posts
Posted December 29, 2019

I made my own mousehelper class with public methods but when i call them nothing happens.I can have the game playing without focus and without it holding my cursor but i cant make it behave like the mouse is moving.This is the only thing left to get it working.If anybody can help me this is the only thing i need

  • Quote

Share this post


Link to post
Share on other sites

ATomo9_CY    0

ATomo9_CY

ATomo9_CY    0

  • Tree Puncher
  • ATomo9_CY
  • Members
  • 0
  • 10 posts
Posted December 29, 2019

Nevermind i fixed it.It works now.I had commented some code that changed the mouse position while trying something else previously and forgot to uncomment it.

I think simulating game input could be important to other modders so if there is any place to show how i did it let me know.ill share the code and changes needed

  • Quote

Share this post


Link to post
Share on other sites

eabjab    0

eabjab

eabjab    0

  • Tree Puncher
  • eabjab
  • Members
  • 0
  • 2 posts
Posted November 30, 2020

I am trying to do something similar and ran into the same issue. Would you mind sharing your solution to change mouse position?

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • chaskuchar
      is there any release i can play past 1.16.4

      By chaskuchar · Posted 23 minutes ago

      i was trying to play 21w0b8 and started it without the controller i use with forge helping me for the controller.  i can start using the lancher a new game like 21w0b8 and the save it after i start.  then i quit and restart the launcher and start forge.  i choose the new game which has 21w0b8 at the link and get a message that it might not be compatible but it starts and the controller is working ok.  now my question is, i think the game only loads for 1.16.4.  i can't find the copper or anything special for the new snapshot.  am i chasing a dead horse trying to play with a controller on a new release???  thanks.  chas
    • Herobrine510
      modded server problems

      By Herobrine510 · Posted 27 minutes ago

      so i just made a modded minecraft server yesterday but i've been getting multiple issues with it like yesterday it was java.lang.nullpointerexception and java.noclassdefounderror. i linked that crash report. and i wanted to link my mods folder but that didnt work so yeah. and now today it's been saying that it can't bind to the port and then it's like "Is there another server running?" when there isnt. i linked that crash report too and i would really appreciate some help.crash-2021-03-03_19.28.04-server.txt crash-2021-03-04_12.22.51-server.txt Oh it says "the state engine was in incorrect state POSTINITIIALIZATION and forced into state SERVER_STOPPED." At least that's what the run.bat file says.run.bat i linked that too but i dont know if it'll help much. crash-2021-03-04_12.22.51-server.txt
    • diesieben07
      java.lang.ExeptionInInitializerError: null

      By diesieben07 · Posted 55 minutes ago

      Show your code.
    • heavengel
      error minecraft this server has mod that requires forge to be installed on client

      By heavengel · Posted 1 hour ago

      Hello   When I try to get in the server there's this message appearing : error minecraft this server has mod that requires forge to be installed on client But it happens that there is NO mod installed on the server, how is this message appearing then ?  Can someone help me please
    • diesieben07
      Can't launch Forge because of spongepowered.[...].MixinTweaker

      By diesieben07 · Posted 1 hour ago

      1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
  • Topics

    • chaskuchar
      0
      is there any release i can play past 1.16.4

      By chaskuchar
      Started 23 minutes ago

    • Herobrine510
      0
      modded server problems

      By Herobrine510
      Started 27 minutes ago

    • We Random
      1
      java.lang.ExeptionInInitializerError: null

      By We Random
      Started 1 hour ago

    • heavengel
      0
      error minecraft this server has mod that requires forge to be installed on client

      By heavengel
      Started 1 hour ago

    • Leetram_519
      1
      Can't launch Forge because of spongepowered.[...].MixinTweaker

      By Leetram_519
      Started 1 hour ago

  • Who's Online (See full list)

    • loordgek
    • hammy3502
    • chaskuchar
    • Ommina
    • ivanbj
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.14.4]Simulate mouse and keyboard input
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community