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

    • Beethoven92
      Error at load_registries event phase

      By Beethoven92 · Posted 6 minutes ago

      Apparently here: BlockList.tutorial_slab = new SlabBlock(Block.Properties.from(BlockList.tutorial_slab)).setRegistryName(location("tutorial_slab")) your BlockList.tutorial_slab block is null when the block registration event is fired..i suggest you use deferred register to manage your registry entries
    • BeardlessBrady
      [1.16.4] Tile Registration

      By BeardlessBrady · Posted 12 minutes ago

      Ah there ya go! Thanks.
    • Beethoven92
      [1.16.4] Tile Registration

      By Beethoven92 · Posted 15 minutes ago

      public VendingTile(TileEntityType<?> tileEntityTypeIn) You don't need an argument in the constructor of your tile entity as in this case is not used since you are passing the TileEntityType to the super class: super(CommonRegistry.TILE_VENDING.get());  
    • BeardlessBrady
      [1.16.4] Tile Registration

      By BeardlessBrady · Posted 25 minutes ago

      Hello, I am having issues registering my tile entity. Here is my code as well as a link to the code in my github. The IDE is complaining that 'TileEntityType.Builder.create' has invalid arguments   // Tiles public static final DeferredRegister<TileEntityType<?>> TILE_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, GOCurrency.MODID); public static final RegistryObject<TileEntityType<VendingTile>> TILE_VENDING = TILE_ENTITY_TYPES.register("vending_te", () -> TileEntityType.Builder.create(VendingTile::new, BLOCK_VENDING.get()).build(null));   https://github.com/Beardlessbrady/Currency-Mod/blob/95230ca4ee2d290b3e5f3ef81810a27f73137625/src/main/java/com/beardlessbrady/gocurrency/handlers/CommonRegistry.java#L42-L43
    • ThisIsNotOriginal
      Error at load_registries event phase

      By ThisIsNotOriginal · Posted 1 hour ago

      The pastebin for the log and Registry Event is posted below this text.   https://pastebin.com/KEzJvRgG https://pastebin.com/VUrXR94k
  • Topics

    • ThisIsNotOriginal
      1
      Error at load_registries event phase

      By ThisIsNotOriginal
      Started 1 hour ago

    • BeardlessBrady
      2
      [1.16.4] Tile Registration

      By BeardlessBrady
      Started 26 minutes ago

    • PlasmaPig13
      1
      The game crashed whilst rendering overlay Error: java.lang.NullPointerException: Rendering overlay Exit Code: -1

      By PlasmaPig13
      Started 1 hour ago

    • EnderiumSmith
      3
      The vanilla tag system isnt suitable for ore dictionary

      By EnderiumSmith
      Started 15 hours ago

    • Ilikecheese
      0
      forge 1.16.5 wont show up

      By Ilikecheese
      Started 1 hour ago

  • Who's Online (See full list)

    • Beethoven92
    • ehbean
    • ThisIsNotOriginal
    • Chumbanotz
    • Microcellule
    • Milk_Shak3s
    • AstroTurffx
    • Jeldrik
    • Azurelmao
    • ichttt
    • Deadlocked47
    • BeardlessBrady
  • 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