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


{{PageSyntax}}
:''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.


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

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

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

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$}} = &quot;&quot;                       '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}} '' ''
'&quot;ClippyBoard&quot; 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}} &quot;user32&quot;
  {{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$ = &quot;Clippy Clipboard (Ctrl+Shift)&quot; '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}} &quot; Press Ctrl+Shift to see clipboard menu.&quot;

{{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;&gt; 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}} &quot; Press Ctrl+Shift to see clipboard menu.&quot;
  {{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$}} = &quot;&quot;
{{Cl|_DELAY}} 1
{{Cl|CLS}}
{{Cl|COLOR}} 11: {{Cl|PRINT}} &quot;Select a letter clipboard option:&quot;
{{Cl|PRINT}}
{{Cl|PRINT}} &quot;A = Address&quot;
{{Cl|PRINT}} &quot;C = Cell phone&quot;
{{Cl|PRINT}} &quot;E = Email&quot;
{{Cl|PRINT}} &quot;F = First Name&quot;
{{Cl|PRINT}} &quot;H = Home phone&quot;
{{Cl|PRINT}} &quot;L = Last Name&quot;
{{Cl|PRINT}} &quot;N = Name&quot;
{{Cl|PRINT}} &quot;M = MAC address&quot;
{{Cl|PRINT}} &quot;P = Password&quot;
{{Cl|PRINT}} &quot;W = Work name&quot;
{{Cl|PRINT}} &quot;X = QUIT!&quot;
{{Cl|PRINT}} &quot;Z = Zip code&quot;
{{Cl|COLOR}} 14: {{Cl|PRINT}}
{{Cl|PRINT}} &quot;Another letter will skip or X = {{Cl|EXIT}}!&quot;

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

{{Cl|SELECT CASE}} K$  'The following text should be your personal user info:
  {{Cl|CASE}} &quot;A&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;my address&quot;
  {{Cl|CASE}} &quot;C&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;cell number&quot;
  {{Cl|CASE}} &quot;E&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;myemail&quot;
  {{Cl|CASE}} &quot;F&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;formal name&quot;
  {{Cl|CASE}} &quot;H&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;home number&quot;
  {{Cl|CASE}} &quot;L&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;lastname&quot;
  {{Cl|CASE}} &quot;M&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;modempassword&quot;
  {{Cl|CASE}} &quot;N&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;name&quot;
  {{Cl|CASE}} &quot;P&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;password&quot;
  {{Cl|CASE}} &quot;X&quot;: {{Cl|END}}
  {{Cl|CASE}} &quot;Z&quot;: {{Cl|_CLIPBOARD$ (statement)|_CLIPBOARD$}} = &quot;zipcode&quot;
{{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)]]


{{PageNavigation}}