'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Dim toolkit As JavaObject
Dim clipboard As JavaObject
Dim data As JavaObject
Dim dataflavor As JavaObject
Dim stringSelection As JavaObject
Dim contents As String
End Sub
Sub AppStart (Args() As String)
' initialize toolit
toolkit.InitializeStatic("java.awt.Toolkit")
' initialize datatypes
dataflavor.InitializeStatic("java.awt.datatransfer.DataFlavor")
' get the system clipboard
clipboard = toolkit.RunMethodJO("getDefaultToolkit",Null).RunMethod("getSystemClipboard",Null)
' read the data on the clipboard
data = clipboard.RunMethod("getContents",Array(Null))
' get the contents of the clipboard as a string
contents = data.RunMethod("getTransferData",Array(dataflavor.GetField("stringFlavor")))
Log("contents : "&CRLF&contents)
' create new clipboard data
stringSelection.InitializeNewInstance("java.awt.datatransfer.StringSelection",Array("hello how are you ?"))
' put onto clipboard
clipboard.RunMethod("setContents",Array(stringSelection,Null))
' read the new data on the clipboard to check it changed
data = clipboard.RunMethod("getContents",Array(Null))
' get the contents of the clipboard as a string
contents = data.RunMethod("getTransferData",Array(dataflavor.GetField("stringFlavor")))
Log("contents : "&CRLF&contents)
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub