Native Clipboard Functions
Liberty BASIC Text windows and Texteditor controls have built-in functions to send text to the Windows clipboard and to retrieve text from the clipboard.
Here are the commands and their explanations.
print #handle, "!copy" ;
This causes the currently selected text to be copied to the WINDOWS clipboard.
print #handle, "!cut" ;
This causes the currently selected text to be cut out of the text window and copied to the WINDOWS clipboard.
print #handle, "!paste" ;
This causes the text in the WINDOWS clipboard (if there is any) to be pasted into the text window at the current cursor position.
print #handle, "!selectall" ;
This causes everything in the text window to be selected.
Accessing the clipboard behind the scenes.
If you have a need to send or retrieve text from the clipboard, you can place a hidden texteditor control on your window. To hide it, simply give it width and height of 0, or give it a location that is outside the window boundaries. Click here for a demo.
To send text to the clipboard:
nomainwin WindowWidth=230:WindowHeight=320 texteditor #1.hide,-400,-400,0,0 texteditor #1.t, 10,10,200,200 button #1.b, "Get Clipboard Text",[getText],UL,10,230 open "Clipboard Demo" for window_nf as #1 #1 "trapclose [quit]" 'put text in hidden texteditor #1.hide "!cls" 'clear #1.hide "This text goes to the clipboard!" wait [quit] close #1:end [getText] 'select text in hidden texteditor #1.hide "!selectall" 'copy selected text to clipboard #1.hide "!copy" 'clear texteditor: #1.t "!cls" 'paste clipboard text into texteditor #1.t "!paste" 'just for demo, select text in texteditor: #1.t "!selectall" ; 'get text into a variable #1.t "!selection? selected$" notice "Text on clipboard was "+chr$(34)+selected$+chr$(34) wait