[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I trap an event  in another application?

Posted on 2001-08-01
6
Medium Priority
?
237 Views
Last Modified: 2010-04-06
I would like to detect when the user executes e.g. a CTRL-C (Copy) command in another application.

When this happens I would like my Delphi application to take control and allow the user to Paste the
information into a Delphi Edit field.
0
Comment
Question by:bjornborg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Accepted Solution

by:
GoodTimes earned 200 total points
ID: 6342597
What you need to do is set a Hook (look into Win32.hlp under SetWindowsHookEx and using the WH_CBT and WH_KEYBOARD Hooks.

Omri
0
 

Expert Comment

by:GoodTimes
ID: 6342605
oops, sorry, forget the WH_CBT. Only use WH_KEYBOARD.

Omri
0
 
LVL 3

Expert Comment

by:rondi
ID: 6343648
Don't forget to put all your hookin code in a DLL
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6345194
Hello

  do you want to hook the events or the clipboard, if you want to spy the clipboard, so if any one press ctrl+c or press copy from the menu, you will get that in ur delphi application, here's a program


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    procedure WMDrawClipboard(var Msg: TMessage);
      message WM_DRAWCLIPBOARD;
 procedure WMChangeCBChain(var Msg: TMessage);
      message WM_CHANGECBCHAIN;

  public
  end;

var
  Form1: TForm1;
  NextInChain : THandle;

implementation

uses ClipBrd;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
NextInChain := SetClipboardViewer(Handle);
end;

procedure TForm1.WMDrawClipboard(var Msg:TMessage);
begin
 if Clipboard.HasFormat(cf_text) then begin
  Memo1.Lines.Clear;
  Memo1.PasteFromClipboard
 end else begin
  //do something with other clipboard formats
 end;
 //pass the message on to the next window
 if NextInChain <> 0 then
  SendMessage(NextInChain, WM_DrawClipboard, 0, 0)
end;

procedure TForm1.WMChangeCBChain(var Msg: TMessage);
var
  Remove, Next: THandle;
begin
  Remove := Msg.WParam;
  Next := Msg.LParam;
 with Msg do
  if NextInChain = Remove then
   NextInChain := Next
  else if NextInChain <> 0 then
   SendMessage(NextInChain, WM_ChangeCBChain,
               Remove, Next)
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  ChangeClipboardChain(Handle, NextInChain);
end;

end.


I hope that what u need

Mohammed
0
 

Author Comment

by:bjornborg
ID: 6355994
Thank you Mohammed,
Your example works fine, but I guess I have to use the SetWindowsHookEx within a DLL as Omri suggested in order to "stop" the current application and transfer the control to the Delphi application.

After having seen the comment/answer from Omri, I have searched for more information about "SetWindowsHookEx" and have found the answer to "Global hooks" which has a detailed and long answer with example application and DLL.

Thanks
Bj?rn
0
 

Author Comment

by:bjornborg
ID: 6356044
The answer points to the routine that must be used, but does not provide solution example (and/or could have pointed to existing example in database)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question