Jump to content

1.12.2 - Manually Fire MouseEvent


Frontear

Recommended Posts

I've created a mod that automatically clicks/uses the item in hand, for people like me who suffer from RSI. The problem here is that I want it to fire a MouseEvent (the forge one) every time it clicks. The reason for this is that another mod, coded by reximian9k, called KeyMod, relies on MouseEvent to update it's cps counter, and I'd like my mod to work correctly with it. Is there a way to manually trigger the MouseEvent, so that any SubscribedMethods will automatically run their code correctly when I use this mod of mine?

I am a human and this action was performed manually. Please contact Frontear if you have any questions or concerns.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

You can call EventBus#post to fire an event. However, there is not just MouseEvent, there is also MouseInputEvent, which is designed to accept the direct LWJGL mouse inputs. I am not sure there is a way to fake those.

Effectively, `MinecraftForge.EVENT_BUS.post(new MouseEvent());`?

I am a human and this action was performed manually. Please contact Frontear if you have any questions or concerns.

Link to comment
Share on other sites

Just now, diesieben07 said:

Correct.

I've tried that, and it still doesn't seem to update the cps counter on reximian9k's mod. I'm certain he uses MouseEvent as well, as it's part of his code.

 

import net.minecraftforge.client.event.MouseEvent;
//...
@SubscribeEvent
public void onClick(MouseEvent e) {
  dx = e.dx;
  dy = e.dy;
  mX = e.x;
  mX = e.y;
  if(e.buttonstate && e.button == Minecraft.getMinecraft().gameSettings.keyBindAttack.getKeyCode() + 100) {
    this.addClick();
    Mainframe.onClick();
  }
  lastEvent = System.currentTimeMillis();
}

 

I am a human and this action was performed manually. Please contact Frontear if you have any questions or concerns.

Link to comment
Share on other sites

You should probably look at where mouse event is normally called and replicate that functionality (It might be a cancellable event)

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Are you sure it’s the same MouseEvent? 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Try stepping through execution with the debugger and/or making your own EventSubscriber to see if the event is fired

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

16 minutes ago, Cadiboo said:

Try stepping through execution with the debugger and/or making your own EventSubscriber to see if the event is fired

 

 

Alright, so I've tried doing some janky stuff, and here are my results.

 

First, I completely made a new class, and had the event binded to `EVENT_BUS.post()` a MouseEvent. This worked, as the reximian9k mod fired. Now here are the issues:

 

The Event will stop posting if any other keys are pressed and the Event itself won't always fire.

 

Edit: It'll stop firing if you change your mouse coordinates, so move it across the screen

Edited by Frontear

I am a human and this action was performed manually. Please contact Frontear if you have any questions or concerns.

Link to comment
Share on other sites

20 minutes ago, Frontear said:

Edit: It'll stop firing if you change your mouse coordinates, so move it across the screen

Is your code getting executed in this situation and it’s only the event not getting fired?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

On 10/25/2018 at 6:12 PM, Cadiboo said:

Is your code getting executed in this situation and it’s only the event not getting fired?

The code is executing perfectly. It's definitely the event

I am a human and this action was performed manually. Please contact Frontear if you have any questions or concerns.

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.