QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: Prithak on December 25, 2018, 05:44:39 am

Title: Copying a string to clipboard
Post by: Prithak on December 25, 2018, 05:44:39 am
Let's say, I have a string a$ and I want to paste it on another mighty program called "notepad". So, I need to copy it in clipboard(pasteboard). Is there a way I can make it so? If yes, tell me how!
Title: Re: Copying a string to clipboard
Post by: Petr on December 25, 2018, 05:51:23 am
Hi Prithak.

A$ = "Hello"
_CLIPBOARD$ = A$

now open Wordpad and press Ctrl + V.

and second way - from text editor Notepad to QB64:

Select something in Notepad, press Ctrl + C

open QB64 and write this code: PRINT _CLIPBOARD$

The same but with pictures do _CLIPBOARDIMAGE

Title: Re: Copying a string to clipboard
Post by: Pete on December 25, 2018, 02:34:23 pm
Here is a fun example. Delays are needed to complete the program transitions. Increase them if it doesn't work on your system.

Code: QB64: [Select]
  1. ' Fun with _CLIPBOARD and _SCREENPRINT
  2. INPUT "I want this to be pasted in Notepad: "; a$
  3. SHELL _DONTWAIT _HIDE "start notepad"
  4. _SCREENPRINT CHR$(22) ' Pastes the input line contents to Notepad after Notepad opens.
  5. ' Clear the clipboard
  6.  
  7. PRINT "Now copy any text from Notepad..."
  8.     _LIMIT 30
  9.     b$ = INKEY$
  10.     IF b$ = CHR$(27) THEN END
  11.     IF _CLIPBOARD$ <> "" THEN _DELAY .5: PRINT "You copied: "; _CLIPBOARD$: EXIT DO
  12.  

Now if you just want to store the contents to the clipboard, to manually paste them, do as Petr explained...

Code: QB64: [Select]
  1. INPUT "I want to be able to paste this in Notepad: "; a$
  2. SHELL _DONTWAIT _HIDE "start notepad"
  3. PRINT "Now click Notepad window and press Ctrl + V to pase the clipboard contents into Notepad..."
  4. PRINT "Press Esc to quit."
  5.     _LIMIT 30
  6.     b$ = INKEY$
  7.     IF b$ = CHR$(27) THEN END
  8.  

Pete
Title: Re: Copying a string to clipboard
Post by: Prithak on December 31, 2018, 09:59:06 pm
Hi Prithak.

A$ = "Hello"
_CLIPBOARD$ = A$

now open Wordpad and press Ctrl + V.

and second way - from text editor Notepad to QB64:

Select something in Notepad, press Ctrl + C

open QB64 and write this code: PRINT _CLIPBOARD$

The same but with pictures do _CLIPBOARDIMAGE
Here is a fun example. Delays are needed to complete the program transitions. Increase them if it doesn't work on your system.

Code: QB64: [Select]
  1. ' Fun with _CLIPBOARD and _SCREENPRINT
  2. INPUT "I want this to be pasted in Notepad: "; a$
  3. SHELL _DONTWAIT _HIDE "start notepad"
  4. _SCREENPRINT CHR$(22) ' Pastes the input line contents to Notepad after Notepad opens.
  5. ' Clear the clipboard
  6.  
  7. PRINT "Now copy any text from Notepad..."
  8.     _LIMIT 30
  9.     b$ = INKEY$
  10.     IF b$ = CHR$(27) THEN END
  11.     IF _CLIPBOARD$ <> "" THEN _DELAY .5: PRINT "You copied: "; _CLIPBOARD$: EXIT DO
  12.  

Now if you just want to store the contents to the clipboard, to manually paste them, do as Petr explained...

Code: QB64: [Select]
  1. INPUT "I want to be able to paste this in Notepad: "; a$
  2. SHELL _DONTWAIT _HIDE "start notepad"
  3. PRINT "Now click Notepad window and press Ctrl + V to pase the clipboard contents into Notepad..."
  4. PRINT "Press Esc to quit."
  5.     _LIMIT 30
  6.     b$ = INKEY$
  7.     IF b$ = CHR$(27) THEN END
  8.  

Pete
Thank you both for answering my question. :D, It was much appreciated!