Paste functionality in Java

Can you use Java to trigger "ctrl+V" functionality? I have found couple questions asked, 0 answered properly or given no snippets of code. https://stackoverflow.com/questions/6631933/how-would-i-make-a-paste-from-java-using-the-system-clipboard http://www.javapractices.com/topic/TopicAction.do?Id=82 1st link does not bother to mention where "jtxtfield" variable came from and if I understand correctly it pastes text from clipboard to predefined field... I want to trigger OS paste function. second link sets and gets clipboard, again, I am not interested in that, I want to trigger ctrl+V fx. for context I am creating app where I have to certain shortcuts binded certain strings. I have all that, I can recognize keys and combinations of keys via JNativeHook library, I can set strings attached to the combinations as well, only thing left is to change System.out.Println(text) to some sort of Clipboard.getContents().out() function or something that takes whatever is in the clipboard and pastes it wherever I am focused at the moment, be it Discord, browser or notepad. screenshot for... context I guess.
Stack Overflow
How would I make a paste from java using the system clipboard?
I want to make a paste from the system clipboard in java. How would I do this?
Java Practices->Clipboard copy and paste
Concise presentations of java programming practices, tasks, and conventions, amply illustrated with syntax highlighted code examples.
No description
31 Replies
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @TwinkleTurd ✨! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
szatkus
szatkus2mo ago
Sounds like something you can trigger with WinAPI. Probably quite painful thing to do in Java.
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
can you see looping over string that is to be pasted and then somehow simulating keystrokes to retype the content somewhat easier? btw I am not sure... I consider myself only slightly stupid but I have written whole description of the problem, now I cannot see it in the Discord UI
dan1st
dan1st2mo ago
Stack Overflow
How to Access Clipboard data using Java in Windows?
I want to Access Clipboard data/text in my Java Program in Windows 10 system targeted program. Any code snippets or Class that is used to access the clipboard data?
dan1st
dan1st2mo ago
Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor)
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
yeah, I know how to "get" the data I want to paste them
dan1st
dan1st2mo ago
you set it in the element if you want to paste it in a textbox, get the textbox and then put the text into it
szatkus
szatkus2mo ago
Stack Overflow
How to paste text using windows paste command to other application ...
How calling interop to paste text using windows pastse command to other application in c#? calling interop? i mean how to programing c# same right click to past text
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
No description
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
no java, sadness
szatkus
szatkus2mo ago
Lol, yes, as I said it's probably painful to do in Java. Unless you find good WinAPI bindings for Java.
dan1st
dan1st2mo ago
you could use the Robot class to trigger ctrl+v but that isn't always that reliable but the question is what exactly you need and why
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
I consider myself only slightly stupid but I have written whole detailed description of the problem, now I cannot see it in the Discord UI, let me try to rephrase myself I want to program where I have keybind, lets say Shift + H, F1, ctrl + escape, whatever...when I press the combination, the string defined in the app pastes/retypes itself? I would call it?
dan1st
dan1st2mo ago
Robot and trigger Ctrl+V maybe
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
ok, you have mentioned reliability where is that coming from? I think I know what you mean, I have seen apps like this leaving out letters etc...
dan1st
dan1st2mo ago
Stack Overflow
My custom "paste from clipboard" action
I want to find a way to do kind of a custom "paste from clipboard" action. Let's assume the content of clipboard is text for simplicity (not a file). Whenever you press Ctrl+V, it inserts that cont...
dan1st
dan1st2mo ago
First, Ctrl+V may not do pasting. Secondly, there are some systems where applications aren't allowed to insert keybinds or paste into other applications at all (e.g. Wayland)
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
yah that sounds whacky enough to try that
dan1st
dan1st2mo ago
well I think it's essentially the same thing with robot again
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
most of the apps I will be using this with are just browser apps and apps that have no reason to protect against that, I will not use this for any hacking or botting, its just simply to help me at work retyping shit again and again yah, I'll try that thanks mate
JavaBot
JavaBot2mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
dan1st
dan1st2mo ago
It isn't from the app. It's about the system not allowing any app to insert keys/paste into any other app
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
ah well, one way to find out
dan1st
dan1st2mo ago
e.g. modern Linux systems
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
mm, 99,9999% of this will be used on windows, maaaaybe mac, we will see, will implement it and see, I wanted to play with Robot anyways
dan1st
dan1st2mo ago
and if the user disables Ctrl+V, it wouldn't work either
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
that's like saying if user uninstalls Discord, he wont recieve discord messages on the device :D, regardless, thanks for thorough reply, will test and try
JavaBot
JavaBot2mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
dan1st
dan1st2mo ago
well they could rebind it to something else
TwinkleTurd ✨
TwinkleTurd ✨OP2mo ago
psychopaths, you are describing psychopaths 😄
JavaBot
JavaBot2mo ago
Post Closed
This post has been closed by <@232832706487123968>.
Want results from more Discord servers?
Add your server