Jump to content

Triggering a GUI Left Click - Creative solutions?


ecumene

Recommended Posts

Hi all!

I'm new to this forum, and this problem has been bugging me for quite some time! What I'm trying to do is cause a left-click/drag or any other mouse event at coordinates in all GUIs (including over-GUI's like NEI) using forge. It's for a mod that adds partial controller support. 

 

My possible solutions so far have been:

 

Using the Java AWT Robot

This one sucks. For a lot of reasons. 

Here's how the robot works

Robot robot = new Robot();
//...
robot.moveMouse(absoluteScreenX, absoluteScreenY)
robot.mousePress(InputEvent.BUTTON_1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON_1_DOWN_MASK);

Absolute coordinates are terrible, because the only absolute position on screen is the Display.getX() and Display.getY(), which only give you coordinates of the point above the title bar. Which means I have to add a Y value per every Window Manager under the sun, or figure it out through crappy methods that are probably different through every OS. Plus I don't know why, but under my experiments, LWJGL2 doesn't pick up these events, but the OS does (Weird, right?). 

Using ASM to attach custom code to Mouse.next() and using Mouse.setPosition() to set the mouse coordinates on screen

This one's pretty challenging, and it would require quite a bit of work. It also would break on LWJGL 3's Minecraft inclusion sometime in the future. It would involve writing bytecode that asks my mod if any mouse events should be added to the ones it's currently reading of the main mouse pointer. It's universal and works, but it's challenging, a bad design, and could cause slower load times (I think?? Idk.)

Invoking the button's "On Click" myself, replicating any forge events, crying over my keyboard

This one requires reflection method invoking, doesn't play well with new forge versions, and overall would be a bad design logistically. It could be one easy road, but I wouldn't do it if there was some easier way. This option would be my last resort.

 

Any help with this would be greatly appreciated! Thank you so much for reading! 

Edited by ecumene
Just adding info
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.