====== The Clipboard ====== Orx now supports clipboards! We can demonstrate this by allowing the user to paste in some text, and have the text replace a text object. First there's a little setup. Start by using [[en:tutorials:projects:creating_your_own_project|init to create a default project]]. Next, define the Control-V key which is the usual for paste, except in the case of Mac OS X: [MainInput] KEY_ESCAPE = Quit KEY_LCTRL = Paste KEY_V = Paste CombineList = Paste To make it more interesting, let's change the default object into a text object which we will update with text from the clipboard. Change the ''[Object]'' in the config to be a text object: [Object] Graphic = TextGraphic Pivot = center Scale = 1 Position = (-90, -30, 0) [TextGraphic] Text = Sentence [Sentence] String = "Paste into this window." Set the object variable and the top of the code: orxOBJECT *object; Then assign to the object variable in the init() function: object = orxObject_CreateFromConfig("Object"); Compile and run, and you'll have a window with a text object like this: {{ tutorials:display:clipboard-window.png |}} In the Run() function (or an update function), check for the Control and V keys, call a get from the clipboard, and send the output to the text object: if (orxInput_HasBeenActivated("Paste")){ const orxSTRING clipboardText = orxSystem_GetClipboard(); orxObject_SetTextString(object, clipboardText); } Compile and run. Go to a text editor and copy some text with Control-C into the system clipboard. Come back to the Orx game window and press Control-V. The object will take the text from your clipboard. Nice! {{ tutorials:display:clipboard-window-paste.png |}} If you attempt copy and paste a file, a bitmap, or any other non-textual information into Orx, the clipboard will contain ''orxNULL''. You can also send copied text back into the clipboard. First, set up the keybinding: [MainInput] KEY_ESCAPE = Quit KEY_LCTRL = Copy # Paste KEY_C = Copy KEY_V = Paste CombineList = Copy # Paste In the Run() function (or an update function), set the clipboard text with: if (orxInput_HasBeenActivated("Copy")){ const orxSTRING clipboardText = "Hello from Orx."; orxSystem_SetClipboard(clipboardText); } Compile and run. Press Control-C to set the clipboard with the "Hello from Orx." text. Now paste into a text editor to get the text from the clipboard: {{ tutorials:display:paste-into-notepad.png |}} You can also work with the clipboard in the [[en:tutorials:config:guide_to_the_orx_console|Orx Console]]. Go to a text editor and copy some text. Go back your Orx application and open the console. Enter: ''Clipboard.Get'' : Hello from outside of Orx From here you can set the clipboard text with: ''Clipboard.Set "Hello from Orx"'' : true Note that quotes are needed when there is whitespace in the text. Now paste the text into a text editor.