给你一个鼠标钩子的代码,稍改一下就能实现你要的功能。主窗口:
function EnableHotKeyHook: BOOL; external 'HKTEST.DLL';
function DisableHotKeyHook: BOOL; external 'HKTEST.DLL';procedure TForm1.Button1Click(Sender: TObject);
begin
  if EnableHotKeyHook then
    ShowMessage('HotKey Testing...');
end;procedure TForm1.Button2Click(Sender: TObject);
begin
  if DisableHotKeyHook then
    ShowMessage('HotKey Testing..., DONE!!');
end;钩子工程文件:
library HKTest;uses
  HKProc in 'HKProc.pas';exports
  EnableHotKeyHook,
  DisableHotKeyHook;begin
  hNextHookProc := 0;
  procSaveExit := ExitProc;
  ExitProc := @HotKeyHookExit;
end.钩子单元文件:
unit HKProc;interfaceuses
  Windows, Messages;var
  hNextHookProc: HHook;
  procSaveExit: Pointer;procedure HotKeyHookExit;
function mouseHookHandler(iCode: Integer;
  wParam: WPARAM;
  lParam: LPARAM): LRESULT; stdcall;
function EnableHotKeyHook: BOOL;
function DisableHotKeyHook: BOOL;
implementationfunction mouseHookHandler(iCode: Integer;
  wParam: WPARAM;
  lParam: LPARAM): LRESULT; stdcall;
begin
  Result := 0;
  If iCode < 0 Then
  begin
    Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
    Exit;
  end;  if ((wParam = wm_rbuttondown)or(wparam = WM_LBUTTONDBLCLK))
     and(globalfindatom('appactivated')<>0) then
  begin
    Result := 1;
    WinExec('Notepad.exe', sw_normal);  // 记事本
  end;
end;function EnableHotKeyHook: BOOL; export;
begin
  Result := False;
  if hNextHookProc <> 0 then Exit;
  // 挂上 WH_mouse 这型的 HOOK, 同时, 传回值必须保留下
  // 来, 免得 HOOK 呼叫链结断掉
  hNextHookProc := SetWindowsHookEx(WH_mouse,
    mouseHookHandler,
    HInstance,
    0);
  Result := hNextHookProc <> 0;
end;function DisableHotKeyHook: BOOL; export;
begin
  if hNextHookProc <> 0 then
  begin
    UnhookWindowshookEx(hNextHookProc);  // 解除 mouse Hook
    hNextHookProc := 0;
    MessageBeep(0);
    MessageBeep(0);
  end;
  Result := hNextHookProc = 0;
end;procedure HotKeyHookExit;
begin
  // 如果忘了解除 HOOK, 自动代理解除的动作
  if hNextHookProc <> 0 then DisableHotKeyHook;
  ExitProc := procSaveExit;
end;end.

解决方案 »

  1.   

    onmousedown
     if button=mbRight then
     begin
     end;
      

  2.   

    要在窗体外?如果在你的程序之外就用hook吧~~这样的例子有很多,找找看。
      

  3.   

    定时获得屏幕的鼠标值:
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      CurPoint:TPoint;
      Left,Top:integer;
    begin
      GetCursorPos(CurPoint);
      form1.caption:='('+inttostr(CurPoint.x)
          +','+inttostr(CurPoint.y)+')';
    end;
      

  4.   

    定时获得屏幕的鼠标值:
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      CurPoint:TPoint;
      Left,Top:integer;
    begin
      GetCursorPos(CurPoint);
      form1.caption:='('+inttostr(CurPoint.x)
          +','+inttostr(CurPoint.y)+')';
    end;
      

  5.   

    procedure button1.click
    begin
    SetCapture(handle);//start Capture
    end;
    procedure button2.click
    begin
    ReleaseCapture(handle);//end Capture;
    end;
    procedure TForm1.onmousedown
    var
    pt:TPoint;
    begin
            GetCursorPos(pt);
    判断左右键
    end;
      

  6.   

    不管是左键还是右键,你在窗口外单击鼠标时,你的程序肯定失去焦点,只要进行判断即可,代码如下:void __fastcall TForm1::WndProc(TMessage& Message)//Override
    {
      if(Message.Msg==WM_NCACTIVATE)
      {
        if(!(bool)Message.WParam)//失去焦点
        {
          TPoint CurPos;
          
          GetCursorPos(&CurPos);
          //做你想做的事
          //...
        }
      } 
    }
      

  7.   

    我不懂VC 用DELPHI如何写?
      

  8.   

    procedure tform1.wndproc(message:tmessage);override;
    var
      curpos:tpoint;
    begin
      if (Message.Msg=WM_NCACTIVATE) then
      begin
        if(Message.WParam=0)//失去焦点
        begin
         
          
          GetCursorPos(CurPos);
          //做你想做的事
          //...
        end;
      end;end;
      

  9.   

    mouse钩子:
    library HKTest;uses
        Windows, Messages;var
        hNextHookProc: HHook;
        procSaveExit: Pointer;function mouseHookHandler(iCode: Integer;
        wParam: WPARAM;
        lParam: LPARAM): LRESULT; stdcall;
    var
        H: thandle;
    begin
        Result := 0;
        if iCode < 0 then
        begin
            Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
            Exit;
        end;    if (wParam = wm_rbuttondown) or (wparam = WM_LBUTTONDown) then
        begin
            Result := 1;
            h := findwindow('TTestForm', 'TestForm');
            if h <> 0 then sendmessage(h, wm_clear, 0, 0);        //WinExec('Notepad.exe', sw_normal);  // 记事本
        end;
    end;function EnableHotKeyHook: BOOL; export;
    begin
        Result := False;
        if hNextHookProc <> 0 then Exit;
      // 挂上 WH_mouse 这型的 HOOK, 同时, 传回值必须保留下
      // 来, 免得 HOOK 呼叫链结断掉
        hNextHookProc := SetWindowsHookEx(WH_mouse,
            mouseHookHandler,
            HInstance,
            0);
        Result := hNextHookProc <> 0;
    end;function DisableHotKeyHook: BOOL; export;
    begin
        if hNextHookProc <> 0 then
        begin
            UnhookWindowshookEx(hNextHookProc); // 解除 mouse Hook
            hNextHookProc := 0;
            MessageBeep(0);
            MessageBeep(0);
        end;
        Result := hNextHookProc = 0;
    end;procedure HotKeyHookExit;
    begin
      // 如果忘了解除 HOOK, 自动代理解除的动作
        if hNextHookProc <> 0 then DisableHotKeyHook;
        ExitProc := procSaveExit;
    end;exports
        EnableHotKeyHook,
        DisableHotKeyHook;begin
        hNextHookProc := 0;
        procSaveExit := ExitProc;
        ExitProc := @HotKeyHookExit;
    end.主程序:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Buttons, OleCtnrs;type
      TTestForm = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Label1: TLabel;
        Label2: TLabel;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
        procedure msghandle(var msg:tmessage);message wm_clear;
      public
        { Public declarations }
      end;var
      TestForm: TTestForm;implementation{$R *.DFM}
    function EnableHotKeyHook: BOOL; external 'HKTEST.DLL';
    function DisableHotKeyHook: BOOL; external 'HKTEST.DLL';procedure ttestform.msghandle(var msg:tmessage);
    var
        pos:tpoint;
    begin
        getcursorpos(pos);
        label1.caption:=inttostr(pos.x);
        label2.caption:=inttostr(pos.y);
    end;procedure TTestForm.Button1Click(Sender: TObject);
    begin
      EnableHotKeyHook;
    end;procedure TTestForm.Button2Click(Sender: TObject);
    begin
      DisableHotKeyHook;
    end;end.