|
Post by honkytonk on Aug 4, 2022 7:39:54 GMT
Hello everyone, I've been trying to save the clipboard (using "texteditor"). Send changes (additions) from the clipboard to a file And I can't. So I come to seek help from the experts. Thank you for.
|
|
|
Post by tsh73 on Aug 4, 2022 8:38:42 GMT
Have a look
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #main.button1, "readClipboard", [button1Click], UL, 26, 16, 122, 25 texteditor #main.log, 22, 51, 496, 300 texteditor #main.hiddenOffScreenTxt, -200, 0, 100, 100 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "read Clipboard demo" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
wait
[quit.main] Close #main END
[button1Click] 'Perform action for the button named 'button1' 'get the data from hidden texteditor #main.hiddenOffScreenTxt "!cls" #main.hiddenOffScreenTxt "!paste" #main.hiddenOffScreenTxt "!contents? string$" 'add it to the logs #main.log time$(); " From clipboard ";len(string$);" bytes" #main.log ">";string$;"<"
wait
|
|
|
Post by honkytonk on Aug 4, 2022 8:55:49 GMT
Well well well, But I would like it to run in the background and send changes to file as they occur (and only changes). I put a gosub [pause 700] and a "goto [[button1Click]+"scan". And I come back to my difficult problem of "stop and go".
|
|
|
Post by tsh73 on Aug 4, 2022 9:32:08 GMT
Ok, here clipboard scanned for changes every 500 ms Only changes are reported (first time *is* a change) Button adds current clipboard to log window even without change
nomainwin
WindowWidth = 550 WindowHeight = 520
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #main.button1, "readClipboard", [button1Click], UL, 26, 116, 122, 25 'texteditor #main.hiddenOffScreenTxt, 0, 0, 500, 100 'you can make ot visible texteditor #main.hiddenOffScreenTxt, 0, -600, 500, 100 'or move it off-screen texteditor #main.log, 22, 151, 500, 300 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "read Clipboard demo" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10" '#main.hiddenOffScreenTxt "!setfocus" '#main.log "!setfocus"
timer 500, [readClip] 'goto [button1Click]
wait
[quit.main] Close #main END
[button1Click] 'Perform action for the button named 'button1' update=1 'force adding to the log even if clipboard not changed [readClip] 'entry point by timer 'get the data from hidden texteditor oldString$= string$ 'print update, oldString$, string$ #main.hiddenOffScreenTxt "!cls" #main.hiddenOffScreenTxt "!setfocus" 'had to add setfocus for JB 2.0 #main.hiddenOffScreenTxt "!paste" #main.hiddenOffScreenTxt "!contents? string$" #main.log "!setfocus" if (update=1) or (oldString$ <> string$ and string$<>"") then 'add it to the logs #main.log time$(); " From clipboard ";len(string$);" bytes" #main.log ">";string$;"<" end if update=0 wait
|
|
|
Post by honkytonk on Aug 4, 2022 11:30:33 GMT
Thank you very much, it works great. I just have to create a new timestamped file for each launch. And it will be very useful
|
|
|
Post by honkytonk on Aug 4, 2022 15:14:08 GMT
I assume it's more difficult (or impossible?) to start with the empty "log"? Is it possible ?
|
|
|
Post by honkytonk on Aug 4, 2022 15:42:28 GMT
I put this before the "timer", it starts with the empty log.
#main.hidTxt "!paste" #main.hidTxt "!contents? string$" if string$ <> "" then #main.hidTxt "!cls" #main.hidTxt "!copy"
And I put a line of: "-----" between each record. But it adds two empty lines at the top of the file Two empty lines at each re-launch. And one empty line after each "append" of the file. I would love to fix that.
|
|
|
Post by Rod on Aug 4, 2022 16:30:25 GMT
You need the trailing ; to stop adding the CrLf pair
So print #file string$;
|
|
|
Post by honkytonk on Aug 4, 2022 16:49:13 GMT
You need the trailing ; to stop adding the CrLf pair So print #file string$; Oh yess, it's véry good, thank you for the important little: ";".
|
|
|
Post by tsh73 on Aug 4, 2022 19:50:31 GMT
I think using clipbaord this way always end up with NewLine appended to text. but you can use
trim$(string$) - it removes CR LF as well as spaces (if you do not care of spaces that is)
|
|
|
Post by honkytonk on Aug 5, 2022 8:39:24 GMT
Houla, if I remove the spaces it will be difficult to read. What is surprising is that we have to takes the: ";" in: print #file string$; To avoid skip line. But that: print #f, "-----------" without ";" do not skip lines. I think the software is now functional. I put it there --->: libertybasic.fr/forum/topic-647+presse-papier.phpThank you for your help.
|
|