Jump to content

Java - mouse clicks and keyboard functions

3 minutes ago, Pachuca said:

Hi,

 

Does anyone know how I can get Java to perform a mouse click operation or have it perform keyboard functions like ctrl+c to copy text into the clipboard than set a variable equal to what's in the the clipboard?

are you trying to make an automated program? Just use auto it - its simlar to c programming and it's way easier

Link to post
Share on other sites

Just now, gtx1060=value said:

are you trying to make an automated program? Just use auto it - its simlar to c programming and it's way easier

Well, I'm using autohotkey right now for some data entry stuff, but I'm trying to switch to Java and I don't know how to get java to do the same stuff. My program pulls information from a website than enters the data into another software client the way a person would do it. I would like to know if anyone knows how to simulate things like mouse clicking or doing copy/paste with java code.

Link to post
Share on other sites

6 minutes ago, Nuluvius said:

You should be more specific as there may well be a much easier solution.

I'm taking text values from a website and assigning it to variables. I need to simulate a mouse click/ mouse drag/ copy-paste as if a person were doing it in order to enter the website information into a client. I don't have any way to interact with the client other than simulating the data entry as if a person were doing it manually with mouse clicks and copy/paste or simply entering values. I also need to check the information that might already exist in the  client with the website information than verify if it's the same or not to determine if further data entry is required. It's using mostly text and dates from the website than entering that information into a client using mouse/keyboard simulation. What else would you need to know?

 

Edit: This is kind of what i'm looking for, but I'm having trouble figuring it out still... 

http://stackoverflow.com/questions/19185162/how-to-simulate-a-real-mouse-click-using-java

Link to post
Share on other sites

19 hours ago, Pachuca said:

What else would you need to know?

Well I was just tying to get a sense of whether you'd considered if it would be possible via import and export to this 'client', either directly or indirectly. Is the UI really the only method that you have available - nothing else? The website on the other hand can easily be scrapped for data so you could make life easier in that regards...

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

2 hours ago, Nuluvius said:

Well I was just tying to get a sense of whether you'd considered if it would be possible via import and export to this 'client', either directly or indirectly. Is the UI really the only method that you have available - nothing else? The website on the other hand can easily be scrapped for data so you could make life easier in that regards...

yes the ui is the only way for me to get this information into it. The website part is already done. I'm going to try using something like InputEvent.MOUSE_BUTTON1_DOWN and see how it will work.

Link to post
Share on other sites

13 hours ago, Pachuca said:

yes the ui is the only way for me to get this information into it. The website part is already done. I'm going to try using something like InputEvent.MOUSE_BUTTON1_DOWN and see how it will work.

Then you are indeed stuffed. Perhaps the Robot class may be of some assistance.

The single biggest problem in communication is the illusion that it has taken place.

Link to post
Share on other sites

13 hours ago, Pachuca said:

yes the ui is the only way for me to get this information into it. The website part is already done. I'm going to try using something like InputEvent.MOUSE_BUTTON1_DOWN and see how it will work.

It's possible to write a js script that follows the behavior you want (make clicks, input values, read values).

I used to work with a framework called Protractor which I believe is quite close to what you want to do. I'm sure, if you look a bit, you'll be able to find a similar framework not so specific so you can adapt it to your needs

The best way to measure the quality of a piece of code is "Oh F*** "s per line

Link to post
Share on other sites

Depending how your website is built you could use something like Selenium (has libraries for most languages as well as an in-browser IDE) or Capybara (RoR) to automate interactions with the website.

AMD Ryzen 7800 X3D, MSI B650 Project Zero, Antec C5, Gigabyte RTX 4080 Super Aero

 

Nikon D500 | Nikon 300mm f/4 PF  | Nikon 200-500 f/5.6 | Nikon 50mm f/1.8 | Tamron 70-210 f/4 VCII | Sigma 10-20 f/3.5 | Nikon 17-55 f/2.8 | Tamron 90mm F2.8 SP Di VC USD Macro | Neewer 750II

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×