-3

How can i receive a message when the user paste anything like txt,... to desktop or anywhere else and not only inside my delphi application. I need paste message when it doing from popup menu and pressing Ctrl+V. Something like the below code :

if (Msg.Message = WM_PASTE) Then
 ShowMessage('Paste');

Imagine an application that has two buttons that one of theme[button1] doing paste from clipboard and another one[button2] doing paste some text from memo1 [I added some text to this memo] to everywhere. the problem is when i doing copy anything to clipboard and then do paste it, next if i do paste by clicking on the button2 ill miss my last clipboard value. I added another memo2 [This memo is my alternative clipboard] and when doing paste by clicking on first button i also paste it into memo2. In the next step i click on button2 this must do paste memo1 value to everywhere that i want now i can also copy the memo2 value to clipboard because i am going to use it again. I can do it if i want to do paste like button2 but if i do paste inside desktop need to detect paste time. An important thing i have to use copy paste instead of send keystroke .

M.MARAMI
  • 95
  • 9
  • 2
    This is pretty hard to do. Applications can choose to implement pasting however they please. Sometimes there will be `WM_PASTE` messages, but many times not. Sometimes the app handles the keyboard shortcuts directly. Sometimes it's invoked from menus, from buttons, from ribbons. What lies behind this request. Why do you want to do this? Perhaps there is a better way. – David Heffernan Jan 20 '17 at 08:42
  • Thank you. That's very difficult to explain but all of things i need to do is only detect keyboard shortcuts directly and from menus. – M.MARAMI Jan 20 '17 at 09:43
  • Why do you want to do this? Because your current ideas are not likely to work out. – David Heffernan Jan 20 '17 at 09:45
  • 2
    Perhaps you need to monitor clipboard contents changing? Look at SetClipboardViewer etc – MBo Jan 20 '17 at 10:25
  • I think that you should try to explain what you are trying to do, even if it is difficult. The clipboard is designed to handle multiple formats, for instance, and it may be that another approach is better, and that it is the copy you need to be looking at rather than the paste. – Dsm Jan 20 '17 at 10:51
  • @M.MARAMI Personally I'm very skeptical of any application that attempts to act _beyond the "boundaries" of its scope_. Even setting aside the potential for nefarious motives, the problem is: that despite your most sincere and honest intentions, you ***cannot know*** what all applications a users interacts with are trying to do. You could without realising it write something that _actively interferes_ with a user's experience. E.g. If a user repeatedly pastes/duplicates a graphic into an image editor - how would your application that "jumps in" on these paste events affect the program? – Disillusioned Jan 20 '17 at 10:59
  • As others have said - you should explain the X part of your XY problem. – Disillusioned Jan 20 '17 at 11:00
  • Please see the question because i edit it again. – M.MARAMI Jan 20 '17 at 11:01
  • 1) "_if i do paste by clicking on the button2 ill miss my last clipboard value_" Pasting does not and ***should not ever*** affect the contents of the clipboard. 2) It sounds like you're trying to implement a clipboard manager? Something that keeps record of multiple things to paste. If that's the case then you don't want to react on `Paste`, you should react on `Copy`. So take a look at @MBo 's comment. – Disillusioned Jan 20 '17 at 11:07
  • It looks to me like a big problem that you face is that you are confused between the terms copy and paste. Copy modifies the clipboard's contents, paste does not. – David Heffernan Jan 20 '17 at 11:33
  • Yes i had a big mistake . Is it possible save clipboards values as temporary in variable? – M.MARAMI Jan 20 '17 at 12:58
  • @M.MARAMI Of course it is. The fact that you're asking suggests you haven't even attempted to do so yet. I'm not going to write a clipboard manager for you. (If that's what you're trying to do - you didn't answer the question.) _That would be far too broad._ You should see how far you can get by yourself. And if you get stuck, ask a specific question. – Disillusioned Jan 20 '17 at 22:46

1 Answers1

0

Try to google about windows hooks like (hook a service to keyboard) or (Intercept Keyboard Input) and you can start from there.

take a look on this it might be useful too:

How to monitor the keyboard above all other applications and then send other keys to them instead

Community
  • 1
  • 1
Dreamer64
  • 923
  • 2
  • 13
  • 30