Facepunch / garrysmod-requests

Feature requests for Garry's Mod
83 stars 24 forks source link

Add GetClipboardText() along with SetClipboardText() #565

Closed ARitz-Cracker closed 9 months ago

ARitz-Cracker commented 8 years ago

So, we can set the clipboard, why can't we get it? What if I want a "paste" button in a 2D3D menu beside a "copy" button?

bmwalters commented 8 years ago

privacy concerns; just make your own "clipboard" with lua

ottworks commented 8 years ago

^

ARitz-Cracker commented 8 years ago

What if I want to copy text from the chatbox or outside GMod to paste somewhere on my menu? If we're that paranoid over privacy concerns, can't we clear the clipboard on game startup?

SwadicalRag commented 8 years ago

What if someone copies something while the game is running?

ottworks commented 8 years ago

What's wrong with ctrl-v?

ARitz-Cracker commented 8 years ago

I currently am coding something that everything is handled within a 2D3D menu, the goal is for it to be fully immersive without it opening up any sort of dialogue box. I could have a paste button where it opens up a Derma_StringRequest but I'm a perfectionist and I want CTRL+V to work with my system. CTRL+C and CTRL+X would work since we have the set function.

But I see other people's point. Something could be getting clipboards every frame like a malicious server or something. It would be a very useful feature for legitimate users. Maybe the user can choose what addon can access the clipboard?

Or (a worse idea) is to notify the user when an addon calls that function... but spam... and... it really makes this a bigger idea than it should be.

Writing a hook that constantly scans for CTRL + C or X is almost just as intrusive imo.

ottworks commented 8 years ago

Compromise: A hook that's called when the user presses CTRL + V ingame.

Velkon commented 8 years ago

Just do it quickly, Isn't it easy?

ARitz-Cracker commented 8 years ago

... the text would go nowhere because a text box isn't being selected.

SwadicalRag commented 8 years ago

Writing a hook that constantly scans for CTRL + C or X is almost just as intrusive imo.

There is no way to get text selected from outside Garry's Mod, nor any text in the clipboard. This is hardly intrusive. The compromise that @DaaOtt and @zerfgog were talking about is to make your own clipboard system that copies text from text elements in-game, or whenever Control V is pressed (meaning the user intentionally wanted to paste data in). This effectively stops any lua scripts from 'accidentally' or 'intentionally' getting sensitive clipboard data, while still being able to get "clipboard" information.

ARitz-Cracker commented 8 years ago

I understand the compromise, but if the user wants to copy something from the chatbox, and I know that CTRL+X or C is pressed, I won't know what text is currently being selected.

Velkon commented 8 years ago

http://wiki.garrysmod.com/page/gui/SetMousePos http://wiki.garrysmod.com/page/gui/InternalMousePressed Done.

SwadicalRag commented 8 years ago

@Velkon, the default in-game chatbox has a scrollbar. Unless you want to emulate the whole chatbox, including the scrolling system in order to get the text the mouse is over (which is overkill and too much effort), those functions are pointless.

SwadicalRag commented 8 years ago

@ARitz-Cracker, mm. Yeah, there is no non-hacky way to get that to work. To be completely honest, a GetClipboardText function would be awesome, but there's no reliable way to prevent sensitive data from being passed into a lua script. I don't usually copy my own passwords, credit card numbers or addresses, but I don't want to regret having done so on a malicious server that logs all clipboard information without my knowledge.

bmwalters commented 8 years ago

@ARitz-Cracker When you ctrl+c/x on a chatbox, doesn't the text go to your system clipboard? From there you can just have the user ctrl+v to paste into whatever.

ARitz-Cracker commented 8 years ago

@zerfgog I am not a derma text box or anything like that, I am a 3D2D system.

bmwalters commented 8 years ago

I see your point

SwadicalRag commented 8 years ago

On second thought https://wiki.garrysmod.com/page/Panel/Paste could do something with that

bmwalters commented 8 years ago

Aha! lmfao:

-- untested
local dummy = vgui.Create("DTextEntry")
dummy:ParentToHUD()
dummy:Hide()
dummy:SetText("")
function GetClipboardText()
     dummy:Paste()
     local contents = dummy:GetText()
     dummy:SetText("")
     return contents
end
ARitz-Cracker commented 8 years ago

@zerfgog I was just about to comment on doing something like that. (Nice, btw!)

But if we could do it in a hackish way, why not do it in a clean way?

ARitz-Cracker commented 8 years ago

Clip Code works, btw. :D thanks for the hack!

bmwalters commented 8 years ago

np, privacy concerns though D:

ARitz-Cracker commented 8 years ago

Had to be modified a bit since Derma sometimes doesn't work right when autorun is loaded.

local dummy
hook.Add("InitPostEntity", "Privacy Stealer", function()
    dummy = vgui.Create("DTextEntry")
    dummy:ParentToHUD()
    dummy:Hide()
    dummy:SetText("")
end )
function GetClipboardText()
    local contents
    if dummy then
        dummy:Paste()
        contents = dummy:GetText()
        dummy:SetText("")
    end
    return contents
end
willox commented 8 years ago

I love mature server owners such as @noiwex looking at my potentially confidential information

bmwalters commented 8 years ago

I usually don't clear my clipboard after taking a screenshot with sharex. I screencap/upload some private stuff sometimes.

bmwalters commented 8 years ago

@Noiwex Christ are you on cocaine? ShareX sets your clipboard to the url of the screencapped image. How is this issue posted "for the sake of attention"? It's a valid request.

bmwalters commented 8 years ago

IT WAS AN EXAMPLE. Are you telling me that you clear your clipboard manually after every piece of sensitive or personal information that you copy?

bmwalters commented 8 years ago

Well, I stand corrected. However, imagine a DarkRP server with 45-50 players consistently, with an owner who grabs all the users' clipboard text and uses regex to find if they're an image or a chat log, then logs them if they are.

bmwalters commented 8 years ago

Is Microsoft willing to dox or blackmail you over those links?

robotboy655 commented 8 years ago

There's a difference between a random dude on the internet stealing your passwords and a massive corporation stealing your passwords.

bmwalters commented 8 years ago

Nice rebuttal.

robotboy655 commented 8 years ago

Yeah, because everyone is obviously less important then you are.

robotboy655 commented 8 years ago

Instead of whining you could've helped finding a solution. This is in your own interests.

mcd1992 commented 8 years ago

Noi pay attention to what's going on. You've been banned from the github for a reason, lots of people are arguing with you for a reason.

You're wrong. Take a look in the mirror and realize the problem isn't other people, its you. You're letting your emotions speak first and not thinking what you say though. Calm down and think/test things before you post on fp/github and people will take you more seriously.

ARitz-Cracker commented 8 years ago

Usually I like to give benefit of the doubt, but petty arguments like this only make me realize more why we can't trust everyone with power like this. The argument that we should have access to private data because the big guys do it is a terrible argument. I always believe that as an indie guy building himself up for his future, I should always do better than the idiots before me. Both with morals, and skills. This is a useful good feature, but it needs some enforcement in place to make sure idiots on a power trip don't... well... go on a power trip.

How about... a hook? A function that is called while the game is in focus and the player presses CTRL + V (or CMD + V on mac) It can still be a bit harmful I admit since you don't know what addon is getting the pasted information, but at least information is being handed to GMod when the user expects it.

garryspins commented 1 year ago

With the addition of the permission system this should be reconsidered.

dvdvideo1234 commented 9 months ago

Not only others I see..