Author Topic: Copying a string to clipboard  (Read 3259 times)

0 Members and 1 Guest are viewing this topic.

Offline Prithak

  • Newbie
  • Posts: 56
  • Life itself is a Programming Language!
    • View Profile
    • My Programming Language
Copying a string to clipboard
« 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!
CLS
IF computer$ = "ON" THEN
me$ = "Happy!"
ELSE
me$ = "Time To Draw!"
END IF
END

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Copying a string to clipboard
« Reply #1 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

« Last Edit: December 25, 2018, 05:55:46 am by Petr »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Copying a string to clipboard
« Reply #2 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
« Last Edit: December 25, 2018, 02:41:23 pm by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Prithak

  • Newbie
  • Posts: 56
  • Life itself is a Programming Language!
    • View Profile
    • My Programming Language
Re: Copying a string to clipboard
« Reply #3 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!
CLS
IF computer$ = "ON" THEN
me$ = "Happy!"
ELSE
me$ = "Time To Draw!"
END IF
END