Jump to content
Attila Kovacs

In-App Clipboard

Recommended Posts

Hi all,

 

Is there any existing unit/module whatever for handling In-App clipboard functionality?

App should not leak data over clipboard, but I would like to keep the feature inside the app.

 

It's shouldn't be too hard, I'm just curious if there is already any solution.

 

Handling text is sufficient.

 

(VCL/Windows)

Edited by Attila Kovacs

Share this post


Link to post

It's unclear what do you mean. From description, following should do what you want (half-pseudocode)

var Clip: string = '';

procedure TForm1.ControlOnKeyDown(Sender, Key, Shift);
begin
  if Shift=[ssCtrl] then
    if Key = VK_C then
      Clip := Sender.SelectedText
    else
    if Key = VK_V then
      Sender.SelectedText := Clip;
end;
    

 

Share this post


Link to post
2 hours ago, Attila Kovacs said:

Hi all,

 

Is there any existing unit/module whatever for handling In-App clipboard functionality?

App should not leak data over clipboard, but I would like to keep the feature inside the app.

 

It's shouldn't be too hard, I'm just curious if there is already any solution.

 

Handling text is sufficient.

 

(VCL/Windows)

@Attila Kovacs you might have to end up writing your own app specific clipboard because the Windows clipboard content is accessible to all running programs.

Share this post


Link to post
7 minutes ago, Ugochukwu Mmaduekwe said:

you might have to end up writing your own app specific clipboard

Thanks @Ugochukwu Mmaduekwe, no problem, I just wanted to inform if there is already something for that.

I'll check hooking up some windows messages.

  • Like 1

Share this post


Link to post
16 hours ago, Dany Marmur said:

would not https://github.com/DelphiPraxis/The-Drag-and-Drop-Component-Suite-for-Delphi be able to provide some functionality for similar tasks?

It's hard to tell from the "crystal clear" requirements but I don't think so.

 

I'm guessing that since the OP is asking for clipboard functionality, and have rejected just copying data to and from a string, that he wants the copy/paste features of the standard Windows common controls used in the application to use his own internal clipboard. That isn't possible.

It would be easy to use the clipboard with a custom data format, that is only understood by his application, but the Windows common controls are hardwired to use the standard CF_TEXT data format which is understood by everyone (thus the data can be considered "leaked").

Share this post


Link to post

so why do you comment on something you don't understand?:)

Especially with ctrl-c/ctrl-v. Is that all how clipboard works in your opinion?:)

 

Share this post


Link to post
2 hours ago, Attila Kovacs said:

Especially with ctrl-c/ctrl-v. Is that all how clipboard works in your opinion?:)

I don't think anyone has a clue what you are talking about.

  • Like 1

Share this post


Link to post

Fellas, please. If Attila thinks he gave enough information, you have two options: Either write an answer based on that, or don't write at all. This should please not escalate.

  • Like 2
  • Thanks 1

Share this post


Link to post
5 hours ago, Anders Melander said:

(thus the data can be considered "leaked")

Ah, yes. Did not read the OP, thread properly. Of course.

 

[Stopping here, thanks Sherlock].

Share this post


Link to post

Ok, here is my prototype.

 

- The goal was to keep application data safe from the clipboard.

- It tries only CF_UNICODETEXT to keep safe, every other formats are free to come and go.  (for now?)

- RichEdit does not pass the necessary events, so it needs further client code to protect

- no extended testing yet, but I can assure that this behavior will drive the user crazy 😉

- no performance penalty tests

- no clue what Antivirus programs says for modifying the import table

 

It does capture clipboard events and keeps copied unicode text in a variable instead of the clipboard.

On paste command, it pastes from this variable. (as far my basic paste algo works)

On OS Clipboard change, if it's CF_UNICODETEXT, overwrites the In-App clipboard variable to be able to paste into the app from the outside.

 

I have no clue yet if there are any flaws, but it was lot of fun to make it.

 

InAppClipBrd.pas

Share this post


Link to post
2 hours ago, Rollo62 said:

wouldn't it be an option to register a custom, "secret" clipboard format

I've already suggested that:

On 1/15/2020 at 10:11 AM, Anders Melander said:

It would be easy to use the clipboard with a custom data format, that is only understood by his application

The Windows common controls would not be able to support that format so you'd lose the standard support for copy/paste in all edit controls. There are ways to deal with this but they are not that simple.

Share this post


Link to post

You can't just register a clipboard format and expect that every control starting using it. That's not how windows clipboard works.

My implementation was attached 11 hours ago, need further testing. It looks good so far.

By the way, with the very same unit it would be possible to encrypt the clipboard data too. But I see no use for that, just saying.

 

 

Share this post


Link to post

If lots of people tell you that they don't fully understand your question, I respectfully suggest that you clarify what you are asking. It's easy for us all to write things that we think are clear but find that others don't fully understand. 

 

My guess is that you want to stop your program putting anything onto the Windows clipboard. Exactly how to do that depends very heavily on what controls your program uses. 

  • Like 1
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×