Author Topic: Is there a way to copy data from windows and paste into a running program?  (Read 3451 times)

0 Members and 1 Guest are viewing this topic.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile

Is it possible  to copy a number from the internet and paste it into a program that is asking for data?

Example.  Copy a number from windows calculator with CTRL C and paste it into a program that is asking for input data with CTRL - V
« Last Edit: January 06, 2021, 01:20:52 am by NOVARSEG »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Look up _CLIPBOARD$ in the QB64 Wiki. Simply put, use Ctrl + C to copy and _CLIPBOARD$ will contain that data. To paste it, you need to write some code similar to this...
Code: QB64: [Select]
  1. b$ = INKEY$
  2.     IF LEN(b$) THEN
  3.         SELECT CASE b$
  4.              CASE CHR$(22) ' Paste
  5.              PRINT _CLIPBOARD$
  6.         END SELECT
  7.     END IF
  8. LOOP UNTIL b$ = CHR$(27) ' Esc key.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Change your program's INPUT routine to my ExtendedInput version.

Code: QB64: [Select]
  1. PRINT "Enter some information (CTRL-V works fine for insert): ";
  2. ExtendedInput information$
  3. PRINT "You entered: "; information$
  4.  
  5. SUB ExtendedInput (out$)
  6.     PCOPY 0, 1
  7.     A = _AUTODISPLAY: X = POS(0): Y = CSRLIN
  8.     CP = 0: OldCP = 0 'Cursor Position
  9.     _KEYCLEAR
  10.     DO
  11.         PCOPY 1, 0
  12.         IF _KEYDOWN(100307) OR _KEYDOWN(100308) THEN AltDown = -1 ELSE AltDown = 0
  13.         k = _KEYHIT
  14.         IF AltDown THEN
  15.             SELECT CASE k 'ignore all keypresses except ALT-number presses
  16.                 CASE 48 TO 57: AltWasDown = -1: alt$ = alt$ + CHR$(k)
  17.             END SELECT
  18.         ELSE
  19.             SELECT CASE k 'without alt, add any keypresses to our input
  20.                 CASE 8
  21.                     oldin$ = in$
  22.                     IF CP > 0 THEN OldCP = CP: CP = CP - 1
  23.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2) 'backspace to erase input
  24.                 CASE 9
  25.                     oldin$ = in$
  26.                     in$ = LEFT$(in$, CP) + SPACE$(4) + MID$(in$, CP + 1) 'four spaces for any TAB entered
  27.                     OldCP = CP
  28.                     CP = CP + 4
  29.                 CASE 32 TO 128
  30.                     IF _KEYDOWN(100305) OR _KEYDOWN(100306) THEN
  31.                         IF k = 118 OR k = 86 THEN
  32.                             oldin$ = in$
  33.                             in$ = LEFT$(in$, CP) + _CLIPBOARD$ + MID$(in$, CP + 1) 'ctrl-v paste
  34.                             'CTRL-V leaves cursor in position before the paste, without moving it after.
  35.                             'Feel free to modify that behavior here, if you want it to move to after the paste.
  36.                             'CP = CP + LEN(_CLIPBOARD$)
  37.                         END IF
  38.                         IF k = 122 OR k = 90 THEN SWAP in$, oldin$: SWAP OldCP, CP 'ctrl-z undo
  39.                     ELSE
  40.                         oldin$ = in$
  41.                         in$ = LEFT$(in$, CP) + CHR$(k) + MID$(in$, CP + 1) 'add input to our string
  42.                         OldCP = CP
  43.                         CP = CP + 1
  44.                     END IF
  45.                 CASE 18176 'Home
  46.                     CP = 0
  47.                 CASE 20224 'End
  48.                     CP = LEN(in$)
  49.                 CASE 21248 'Delete
  50.                     oldin$ = in$
  51.                     in$ = LEFT$(in$, CP) + MID$(in$, CP + 2)
  52.                 CASE 19200 'Left
  53.                     CP = CP - 1
  54.                     IF CP < 0 THEN CP = 0
  55.                 CASE 19712 'Right
  56.                     CP = CP + 1
  57.                     IF CP > LEN(in$) THEN CP = LEN(in$)
  58.             END SELECT
  59.         END IF
  60.         alt$ = RIGHT$(alt$, 3)
  61.         IF AltWasDown = -1 AND AltDown = 0 THEN
  62.             v = VAL(alt$)
  63.             IF v >= 0 AND v <= 255 THEN in$ = in$ + CHR$(v)
  64.             alt$ = "": AltWasDown = 0
  65.         END IF
  66.         blink = (blink + 1) MOD 30
  67.         LOCATE Y, X
  68.         PRINT LEFT$(in$, CP);
  69.         IF blink \ 15 THEN PRINT " "; ELSE PRINT "_";
  70.         PRINT MID$(in$, CP + 1)
  71.  
  72.         _DISPLAY
  73.         _LIMIT 30
  74.     LOOP UNTIL k = 13
  75.  
  76.     PCOPY 1, 0
  77.     LOCATE Y, X: PRINT in$
  78.     out$ = in$
  79.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Thanks
looking at the code now.

Also it would be nice to take data from a running program and paste it into windows

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
As an aside to this, the output of Windows CMD commands can be piped to the clipboard, for instance:

SHELL "CMD/C DIR | CLIP"