r/javahelp • • Mar 31 '20

Solved Can java output text as user?

So I'm trying to get java to output certain text on any open window based one the event of certain strings being entered and hitting tab.

It's essentially an autocorrect program that fills in templates.

For example, if I type "wbu" in any text field in any window and follow it with hitting tab, it should replace the previous string "wbu" with "what about you?".

I managed to figure out the logic of reading the keyboard using the native hook library, but I'm completely stuck when it comes to getting any output from my program.

What can I use to have Java output into any text field?

17 Upvotes

16 comments sorted by

12

u/desrtfx Out of Coffee error - System halted Mar 31 '20

Yes, it can. The Robot class is responsible for that.

https://www.geeksforgeeks.org/robot-class-java-awt/

7

u/Jesting_Insomniac Mar 31 '20

You are a life saver!

Thank you very much!!

Finally a year of work is about to end

2

u/Zockerbaum Mar 31 '20

A year of programming or a year of collecting abbreviations?

2

u/Jesting_Insomniac Mar 31 '20

Collecting data and abbreviations, I thought I'd get the annoying part out of the way first.

The coding so far has only taken a couple of hours, and I don't think it should take much more than that, polishing might take a while, but hey, once I have it running I can fix bugs as I go

3

u/Zockerbaum Mar 31 '20

Good, I was already worrying that you were spending a year just on programming this

1

u/Jesting_Insomniac Mar 31 '20

If it took me a year to program this, I'm pretty sure I'd be in the wrong field lol

Sorting through so much data, and formatting it in a way that I could use took quite some time

Some files digitized, the rest on paper, I can't write a tool to sort through everything because of how unreliable the person who was entering the data was.

Or rather, it's just quicker than developing a tool to do it since I'm still very new to software development

3

u/Kambz22 Intermediate Brewer Mar 31 '20

Probably just me being cautious but I'd also make sure you aren't capturing password fields to plain text, especially if you store anything.

But what the user above said will probably work :)

2

u/Jesting_Insomniac Mar 31 '20

Hey kambz, thanks for the advice!

Fortunately, nothing is being stored, it's all fed directly to the logic that the bot will be using, and I'm the only person who will have access to the program on a device that won't be able to connect to the internet, which also I'm the only person who has access to.

So I'd say it's pretty safe :)

3

u/ndm250 Mar 31 '20

I made this a while ago: https://github.com/nmeyvis/flow

It captures and replaces text at the cursor which sounds like what you're doing. Uses Robot like others mentioned

1

u/Jesting_Insomniac Apr 01 '20

Thank you very much!

I'm just about to check it out!

2

u/bwLearnsProgramming Mar 31 '20

Hey man this sounds really interesting to me. Any way I could convince you to share your source code ?

2

u/Jesting_Insomniac Apr 01 '20

Sure thing!

I still need to figure a few things out first, once that's done, I'll publish it on somewhere like github.

Plus, ndm250 published his, which I know is a lot more complete than mine.

I'm about to check it out!

2

u/bwLearnsProgramming Apr 01 '20

I just saw that he posted his :) thanks for pointing out that out. Am definitely looking forward to seeing yours as well.

1

u/Jesting_Insomniac Apr 02 '20

My pleasure, friend! :)

And I wouldn't hold my breath if I were you, haha!

2

u/bwLearnsProgramming Apr 03 '20

No worries. I know how that goes lol

1

u/Jesting_Insomniac Apr 05 '20

Hello there again, so I've made some huge progress, and will be finished very soon with the source code.

Basically all I have left to do is make it read the abbreviations I had from a file, and essentially have the code change what it does based on the abbreviations, and paste what I need pasted.

This is the trouble I'm having at the moment, but i should be able to figure it all out soon.