B4J Question fx.clipboard Paste at cursor

ThRuST

Well-Known Member
Licensed User
Longtime User
How to paste text from the clipboard to the cursor position?
I need code for automatic paste from clipboard, thanks.
btw I've tried fx.clipboard.getstring but that didn't work in notepad!!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Button1_Action
   If fx.Clipboard.HasString Then
     Dim i As Int = TextArea1.SelectionStart
     Dim s As String = fx.Clipboard.GetString
     TextArea1.Text = TextArea1.Text.SubString2(0, TextArea1.SelectionStart) & s & _
       TextArea1.Text.SubString(TextArea1.SelectionEnd)
     TextArea1.SetSelection(i + s.Length, i + s.Length)
     TextArea1.RequestFocus
   End If
End Sub
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Hi Erel, I am using fx.clipboard with the contextmenu example provided by Steve05, so when selecting an item from the menu a string should be pasted at the cursor.
It's outside the form, in any application. So far I can set a string in the clipboard but not paste it automatically at the cursor.
I know this is possible in C sharp but not in B4J. Please help me again!!
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
fx.clipboard.GetString should probably work but nothing is pasted when I call it. Am I missing something out?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You've asked a question. I answered with an example based on the question. It takes time to write such answers.

We cannot guess what exactly you are trying to do. Sorry but I cannot further help you...

I know this is possible in C sharp but not in B4J
I'm not sure why you are writing it in each of your posts. It is not relevant. B4J has nothing to do with C#.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
fx.clipboard.GetString() returns the String contents of the clipboard (if there are any). It doesn't paste anything. If you want to programmatically paste something, you need to invoke the "ctrl_v" or the OS-specific equivalent key combo. The jAWTRobot library can do this for you.
 
Upvote 0
Top