{{DISPLAYTITLE:_CLIPBOARD$}}
The [[_CLIPBOARD$]] function returns the current Operating System's clipboard contents as a [[STRING]].


{{PageSyntax}}
:{{Parameter|result$}} = [[_CLIPBOARD$]]


{{PageDescription}}
* Text returned can contain the entire contents of a copied file or web page or text from a previous [[_CLIPBOARD$ (statement)|_CLIPBOARD$]] statement.
* The string returned can also contain formatting like CRLF ([[CHR$]](13) + [[CHR$]](10)) end of line characters.
* The clipboard can be used to copy, paste and communicate between running programs.


{{PageExamples}}
''Example 1:'' Passing a string value between two running programs no matter where they are located.
: ''Program1:''
{{CodeStart}} '' ''
{{Cl|PRINT}} "Start Program2 to read your text entries! Empty entry quits!"
{{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "Entry program started!"            'set clipboard initially

DO
  {{Cl|LINE INPUT}} "Enter some text to send to other program: ", text$
  {{Cl|IF...THEN|IF}} text$ = "" {{Cl|THEN}} {{Cl|EXIT DO}}
  {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = text$
{{Cl|LOOP}}

{{Cl|SYSTEM}} '' ''
{{CodeEnd}}
:''Program2:''
{{CodeStart}}
{{Cl|PRINT}} "Enter text in Program1 and this program will read it. Esc key quits!"

DO: {{Cl|_LIMIT}} 100
  text$ = {{Cl|_CLIPBOARD$}}                       'function returns clipboard contents
  {{Cl|IF...THEN|IF}} {{Cl|LEN}}(text$) {{Cl|THEN}} 
     {{Cl|PRINT}} text$
     {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = ""                       'clear clipboard after a read
  {{Cl|END IF}}
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27)

{{Cl|END}}  '' ''
{{CodeEnd}}
:''Explanation:'' Compile and run both programs at once to see the interaction. You could also run them on different paths.


''Example 2: A minimized program that pops up when Ctrl + Shift is entered anytime in '''Windows''' and adds clipboard text to be Pasted:
{{CodeStart}} '' ''
'"ClippyBoard" program uses GetKeyState Win API to monitor a specific key combination.
'This demo will maximize the window and focus on program when Shift+A is pressed.

{{Cl|DECLARE DYNAMIC LIBRARY}} "user32"
  {{Cl|FUNCTION}} FindWindowA%&amp; ({{Cl|BYVAL}} ClassName {{Cl|AS}} {{Cl|_OFFSET}}, WindowName$) 'find process handle by title
  {{Cl|FUNCTION}} GetKeyState% ({{Cl|BYVAL}} nVirtKey {{Cl|AS}} {{Cl|LONG}}) 'Windows virtual key presses
  {{Cl|FUNCTION}} ShowWindow&amp; ({{Cl|BYVAL}} hwnd {{Cl|AS}} {{Cl|_OFFSET}}, {{Cl|BYVAL}} nCmdShow {{Cl|AS}} {{Cl|LONG}}) 'maximize process
  {{Cl|FUNCTION}} GetForegroundWindow%&amp; 'find currently focused process handle
  {{Cl|FUNCTION}} SetForegroundWindow&amp; ({{Cl|BYVAL}} hwnd {{Cl|AS}} {{Cl|_OFFSET}}) 'set foreground window process(focus)
{{Cl|DECLARE LIBRARY|END DECLARE}}

title$ = "Clippy Clipboard (Ctrl+Shift)" 'title of program window
{{Cl|_TITLE}} title$ 'set program title
hwnd%&amp; = FindWindowA(0, title$ + {{Cl|CHR$}}(0)) 'find this program's process handle

{{Cl|SCREEN}} 13
{{Cl|_SCREENMOVE}} {{Cl|_SCREENMOVE|_MIDDLE}}

{{Cl|COLOR}} 10: {{Cl|PRINT}}
{{Cl|PRINT}} " Press Ctrl+Shift to see clipboard menu."

{{Cl|_DELAY}} 4
x&amp; = ShowWindow&amp;(hwnd%&amp;, 2) 'minimize

{{Cl|DO...LOOP|DO}}: {{Cl|_LIMIT}} 30 'save CPU usage while waiting for key press

  {{Cl|IF...THEN|IF}} GetKeyState(16) &lt; 0 {{Cl|AND (boolean)|AND}} GetKeyState(17) &lt; 0 {{Cl|THEN}} '&lt;==== Shift+A
    FGwin%&amp; = GetForegroundWindow%&amp; 'get current process in focus
    y&amp; = ShowWindow&amp;(hwnd%&amp;, 1) 'maximize minimized program

    {{Cl|IF...THEN|IF}} FGwin%&amp; &lt;> hwnd%&amp; {{Cl|THEN}} z&amp; = SetForegroundWindow&amp;(hwnd%&amp;) 'set focus when necessary
    {{Cl|_DELAY}} 1
    GetKey
    x&amp; = ShowWindow&amp;(hwnd%&amp;, 2) 'minimize after letter key entry
    {{Cl|COLOR}} 10: {{Cl|PRINT}}
    {{Cl|PRINT}} " Press Ctrl+Shift to see clipboard menu."
  {{Cl|END IF}}
{{Cl|LOOP}}


{{Cl|SUB}} GetKey
{{Cl|CLS}}
{{Cl|COLOR}} 12: {{Cl|PRINT}}: {{Cl|PRINT}} {{Cl|_CLIPBOARD$}}
{{Cl|DO...LOOP|DO}}: {{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|INKEY$}} = ""
{{Cl|_DELAY}} 1
{{Cl|CLS}}
{{Cl|COLOR}} 11: {{Cl|PRINT}} "Select a letter clipboard option:"
{{Cl|PRINT}}
{{Cl|PRINT}} "A = Address"
{{Cl|PRINT}} "C = Cell phone"
{{Cl|PRINT}} "E = Email"
{{Cl|PRINT}} "F = First Name"
{{Cl|PRINT}} "H = Home phone"
{{Cl|PRINT}} "L = Last Name"
{{Cl|PRINT}} "N = Name"
{{Cl|PRINT}} "M = MAC address"
{{Cl|PRINT}} "P = Password"
{{Cl|PRINT}} "W = Work name"
{{Cl|PRINT}} "X = QUIT!"
{{Cl|PRINT}} "Z = Zip code"
{{Cl|COLOR}} 14: {{Cl|PRINT}}
{{Cl|PRINT}} "Another letter will skip or X = {{Cl|EXIT}}!"

K$ = {{Cl|UCASE$}}({{Cl|INPUT$}}(1))

{{Cl|SELECT CASE}} K$  'The following text should be your personal user info:
  {{Cl|CASE}} "A": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "my address"
  {{Cl|CASE}} "C": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "cell number"
  {{Cl|CASE}} "E": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "myemail"
  {{Cl|CASE}} "F": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "formal name"
  {{Cl|CASE}} "H": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "home number"
  {{Cl|CASE}} "L": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "lastname"
  {{Cl|CASE}} "M": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "modempassword"
  {{Cl|CASE}} "N": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "name"
  {{Cl|CASE}} "P": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "password"
  {{Cl|CASE}} "X": {{Cl|END}}
  {{Cl|CASE}} "Z": {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = "zipcode"
{{Cl|END SELECT}}
{{Cl|CLS}}
{{Cl|PRINT}}
{{Cl|PRINT}}
{{Cl|COLOR}} 14: {{Cl|PRINT}} {{Cl|_CLIPBOARD$}}
{{Cl|BEEP}}
{{Cl|_DELAY}} 2
{{Cl|END SUB}} '' ''
{{CodeEnd}}{{small|Code by Ted Weissgerber}}
: ''Explanation:'' The program will run minimized until Ctrl + Shift is entered and will pop up to ask for a letter choice that contains the text you want in the clipboard. More letter choices can be added. Text can be pasted into a web page or entry box and the program will minimize until it is needed later. The program uses very little resources!


{{PageSeeAlso}}
* [[_CLIPBOARD$ (statement)]]
* [[_CLIPBOARDIMAGE (function)]], [[_CLIPBOARDIMAGE]] (statement)


{{PageNavigation}}
<
