Paste From Clipboard

Does anyone know if there’s a way to paste the contents of the clipboard programmatically? The docs talk about pasting from the clipboard into a TextArea but I need to paste the contents into TextFields in a completely different application. Thanks!

Which OS? In macOS there is AppleScript which can access the clipboard. But any AppleScript needs permissions for the controlled app.

Did you read the Docs about Clipboard (Clipboard — Xojo documentation)?

This code checks to see if the Clipboard is text data and if so, copies the contents of the Clipboard to a TextField:

Var c As New Clipboard 
  If c.TextAvailable Then 
  TextField1.Text = c.Text 
End If 
c.Close

Of course, this will only work inside your xojo app, not as a way to exchange data with a second app.

In the past, I used AppleScript to do this very thing but in this case, the end user is on a PC so I don’t think that would work.

Yes, I did read that. But as I said, this needs to interact with a different app.

What do you want to do ?
Better: what do you want to achieve ?

ISn’t it a different way to do what you want ?

I suppose your user cannot use Ctrl-V to Paste the Clipboard Contents…

On Windows in a project in which i had to avoid using PlugIns, i used AutoHotkey to send Data to other Apps.

Well, if that’s what it comes down to then yes, the user can use Ctrl-V but what’s easier, using Ctrl-V or just clicking a button? I’d rather just click a button.

That might ultimately be the solution. I’ll let you know how it turns out. Thanks!

1 Like

My apologies. To answer your question; the user has a lot of data to enter into a database. I’m writing something that will save him the trouble of having to type all that data in manually.

Why not save it directly into the database using your app? Why do it manually? Anyway, glad i could help. :slight_smile:

1 Like

If its really a lot of data to enter - maybe an import file could help - if the target app has import capabilities…

That would be the obvious way to do it, right? Unfortunately, the user works for the state. And he’s too low on the totem poll to be granted access to the database.

1 Like

If the app is a standard win32 app, you can use declares to edit the textboxes from your app.

Just use the windows API FindWindow to get the window and textboxes handler then a SendMessage with WM_SETTEXT to edit the text. Many examples in the forum.

Excellent! I think between yours and Sascha’s suggestions, I have a workable solution. I’ll let you know how everything goes. Many thanks!