Making Code Run in Browser

I am writing a code that finds the X and Y values of the mouse and left-clicks by itself, but what if I wanted it to do the same thing on say, google, I would tell the code to find the X and Y values of the mouse and the code will left-click, but the code is running on the Processing app and the place I want the code to click is on the google app. How would I make the code know that it should do every thing on google ?

It sounds like you’re looking for Java’s Robot class, which allows you to control the mouse and keyboard.

I’d start by googling “java robot class” for a ton of results. Try to get something simple working, like a small example app that moves the mouse to the middle of the screen. Get that working first before you try to do anything more advanced.

Good luck!

1 Like

Also depending on your ultimate goal, you also might want to look into using Google’s search API to get search results through code instead of by clicking the mouse. Depends on what you’re trying to do though.

1 Like

Well I have managed to make simple bot that can find a variable and left-click on it for any 2D video game, so that would be the goal right now. And how does the API work?
Sorry for another one, but does robot class work for Processing.

Processing is written in Java, and anything that works in Java should work in Processing. So yep, the Robot class works in Processing. What happened when you tried it?

APIs allow you to write code that accesses a service like google search. I’d start by googling “google search api” for a ton of results!

1 Like

I don’t know use the robot class, and is the API the thing that pops up when you click inspect on google. Which one do you think would be best and easiest for the video game bot code I have made? So I can focus on that first.

Neither one is going to be easier or harder, they’re just different tools. If you’re not familiar with either one, the best thing you can do is google and put together a small example program that tests out the basic functionality. Good luck!

1 Like

@Kevin will try that starting tomorrow. First I am trying the Robot Class. When I search it up a lot of the results include “Selenium”, what is that all about?

According to the Selnium website:

Selenium automates browsers. That’s it! What you do with that power is entirely up to you. Primarily it is for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should) also be automated as well.

That explains it better than I could!

1 Like