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.
31 Replies
⌛
This post has been reserved for your question.
Hey @TwinkleTurd ✨! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose 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.
Sounds like something you can trigger with WinAPI. Probably quite painful thing to do in Java.
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
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?
Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor)
yeah, I know how to "get" the data
I want to paste them
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
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
no java, sadness
Lol, yes, as I said it's probably painful to do in Java.
Unless you find good WinAPI bindings for Java.
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 whyI 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?
Robot
and trigger Ctrl+V maybeok, 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...
Something like that? https://stackoverflow.com/q/20343716/10871900
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...
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)yah that sounds whacky enough to try that
well I think it's essentially the same thing with robot again
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
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.
It isn't from the app. It's about the system not allowing any app to insert keys/paste into any other app
ah
well, one way to find out
e.g. modern Linux systems
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
and if the user disables Ctrl+V, it wouldn't work either
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
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.
well they could rebind it to something else
psychopaths, you are describing psychopaths 😄
Post Closed
This post has been closed by <@232832706487123968>.