Jump to content




Write into the clipboard


13 replies to this topic

#1 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 27 May 2016 - 10:32 PM

Something like:
(io/os).setClipboard(string/any value, mode)
mode = 'a' -- Like fs.open(path, 'a')
mode = 'w' -- Like fs.open(path, 'w')

EDIT:
I skimmed all the answers, what's about to implement CTRL + C and
(io/os).setClipboard(strinh/any toCopy)
Sets the string, which can be copied with CTRL + C.
The top brass programs (bios.lua[, cc.jar?]) knows, who sends the copy command and sets to their clipboard.

Edited by Sewbacca, 29 May 2016 - 12:44 PM.


#2 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 27 May 2016 - 11:06 PM

How are you going to know which user's clipboard? More than one people can use a CC computer at the same time.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 27 May 2016 - 11:13 PM

Why would I want CC to be able to overwrite the contents of my clipboard without my permission?

#4 Gumball

  • Members
  • 254 posts
  • LocationFairbanks, Alaska

Posted 27 May 2016 - 11:57 PM

 KingofGamesYami, on 27 May 2016 - 11:13 PM, said:

Why would I want CC to be able to overwrite the contents of my clipboard without my permission?

That could be a settings() function somehow.

#5 Waitdev_

  • Members
  • 432 posts
  • LocationAdelaide

Posted 28 May 2016 - 12:20 AM

 BlueBird, on 27 May 2016 - 11:57 PM, said:

 KingofGamesYami, on 27 May 2016 - 11:13 PM, said:

Why would I want CC to be able to overwrite the contents of my clipboard without my permission?

That could be a settings() function somehow.

which could be off by default

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 28 May 2016 - 12:36 AM

The point is that the setting shouldn't be defined by the computer - if you don't want a given system messing with your clipboard, then what's the point in giving that system a function which anyone can use to make it write to your clipboard anyway?

That leaves ComputerCraft.cfg, but even if such a setting were implemented... that still doesn't answer Creator's question. How can you ever be sure you're writing to the correct user's clipboard?

#7 Gumball

  • Members
  • 254 posts
  • LocationFairbanks, Alaska

Posted 28 May 2016 - 05:39 AM

 Bomb Bloke, on 28 May 2016 - 12:36 AM, said:

The point is that the setting shouldn't be defined by the computer - if you don't want a given system messing with your clipboard, then what's the point in giving that system a function which anyone can use to make it write to your clipboard anyway?

That leaves ComputerCraft.cfg, but even if such a setting were implemented... that still doesn't answer Creator's question. How can you ever be sure you're writing to the correct user's clipboard?

Maybe some sort of user environment table that you could use. Maybe something like _players.originalPlayer or _players.index[some number representing a player]

#8 Sebra

  • Members
  • 726 posts

Posted 28 May 2016 - 05:43 PM

 Creator, on 27 May 2016 - 11:06 PM, said:

How are you going to know which user's clipboard? More than one people can use a CC computer at the same time.

 KingofGamesYami, on 27 May 2016 - 11:13 PM, said:

Why would I want CC to be able to overwrite the contents of my clipboard without my permission?
Player should initiate process.
One way for it is to add couple of keys to bind couple of actions:
1.Copy action, initiating special event and allowing special function to send info to clipboard.
2.Paste action, initiating special event with clipboard info as a parameter.

So player would be able to map those actions on his keyboard and know when his clipboard is used.
Lua program would be able to use Copy and Paste actions without any knowledge about affected player and only when the player initiate it.

#9 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 28 May 2016 - 06:59 PM

But given that more than one player can be inside a computer's screen at one time, how could the computer differentiate between different users? What if user A wanted to copy something, but user B had something incredibly important on his clipboard. If person A copied something, how would cc know not to put it onto player B's clipboard?


While I'm a fan of the concept, in practice it would cause more harm than good, and IF Dan were to implement this, then he'd have to create more than just a function to set clipboards, he'd have to differentiate between users and that's just not feasible.

#10 Waitdev_

  • Members
  • 432 posts
  • LocationAdelaide

Posted 29 May 2016 - 02:17 AM

 Dragon53535, on 28 May 2016 - 06:59 PM, said:

But given that more than one player can be inside a computer's screen at one time, how could the computer differentiate between different users? What if user A wanted to copy something, but user B had something incredibly important on his clipboard. If person A copied something, how would cc know not to put it onto player B's clipboard?


While I'm a fan of the concept, in practice it would cause more harm than good, and IF Dan were to implement this, then he'd have to create more than just a function to set clipboards, he'd have to differentiate between users and that's just not feasible.

isn't this pretty much what creator said but in a lot more detail...

 Creator, on 27 May 2016 - 11:06 PM, said:

How are you going to know which user's clipboard? More than one people can use a CC computer at the same time.


#11 CoderPuppy

  • Members
  • 121 posts

Posted 29 May 2016 - 04:46 AM

What about if there was a buffer that was copied from...

So when you select text in a program, the buffer would be set to the contents of the selection (via a setSelection function or something).
Then when a client tries to copy from that computer it reads from the buffer (which could be synced or requested).

#12 Sebra

  • Members
  • 726 posts

Posted 29 May 2016 - 06:34 AM

 Dragon53535, on 28 May 2016 - 06:59 PM, said:

But given that more than one player can be inside a computer's screen at one time, how could the computer differentiate between different users? What if user A wanted to copy something, but user B had something incredibly important on his clipboard. If person A copied something, how would cc know not to put it onto player B's clipboard?
It was directly after my post and answer in my post already. Player, activated Copy action, would get copy, not the others.

 CoderPuppy, on 29 May 2016 - 04:46 AM, said:

What about if there was a buffer that was copied from...

So when you select text in a program, the buffer would be set to the contents of the selection (via a setSelection function or something).
Then when a client tries to copy from that computer it reads from the buffer (which could be synced or requested).
This can work too.
For Copy action Player get copy of buffer (and create event for program to know).
For Paste action Player set buffer and create event for program to make actual paste.
For Cut action Player get copy of buffer and create event to clear buffer and make actual cut.

#13 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 29 May 2016 - 07:41 AM

 CoderPuppy, on 29 May 2016 - 04:46 AM, said:

What about if there was a buffer that was copied from...

So when you select text in a program, the buffer would be set to the contents of the selection (via a setSelection function or something).
Then when a client tries to copy from that computer it reads from the buffer (which could be synced or requested).

As I was reading through the responses, this is the xact solution that came to my mind too. The PC has a function os.toClipboard(), then when a user presses ctrl+c the minecraft client copies the selected text into the clipboard of the user who pressed the keys. A copy event is fired, but this part is not obligatory.

#14 Sewbacca

  • Members
  • 450 posts
  • LocationStar Wars

Posted 29 May 2016 - 12:43 PM

I have edited my question.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users