我想要一段代码,类似屏保机制,如果鼠标一分钟(时间可设置)没有动,就自动划原。请给段代码

解决方案 »

  1.   

    要代码,好直接啊……
    汗%&*##
      

  2.   

    用全局鼠标HOOK实现,如果不是全局的只是单应用的改下
    SetWindowsHookEx(WH_MOUSE, @HookProc, 0, GetCurrentThreadId);
    //DLL
    uses
      SysUtils,
      Windows,  {钩子函数都来自 Windows 单元}
      Messages, {消息 WM_LBUTTONDOWN 定义在 Messages 单元}
      Classes;
    {$R *.res}var
      gHook: HHOOK; {钩子变量}
      gHandle: THandle;const
      WM_MouseMsg = WM_User + 1;  
    function HookProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
    begin
      if gHandle > 0 then
        PostMessage(gHandle,WM_MouseMsg,wParam,lParam);
      Result := CallNextHookEx(gHook, nCode, wParam, lParam);
    end;function SetHook: Boolean; stdcall;
    begin
      gHook := SetWindowsHookEx(WH_MOUSE, @HookProc, HInstance, 0);
      Result := gHook <> 0;
    end;function DelHook: Boolean; stdcall;
    begin
      Result := UnhookWindowsHookEx(gHook);
    end;procedure RegisterHandle(AHandle: THandle);stdcall;
    begin
      gHandle := AHandle;
    end;exports
      SetHook,
      DelHook,
      RegisterHandle;//应用unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;const
      WM_MouseMsg  = WM_USER + 1;type
      TForm1 = class(TForm)
        Button1: TButton;
        Timer1: TTimer;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        procedure FormShow(Sender: TObject);
      private
        FIncrement: Int64;  //秒
        procedure WMMouseMsg(var Msg: TMessage);message WM_MouseMsg;
      public
        { Public declarations }
      end;var
      Form1: TForm1;  function SetHook: Boolean; stdcall;external 'MouseHook.dll';
      function DelHook: Boolean; stdcall;external 'MouseHook.dll';
      procedure RegisterHandle(AHandle: THandle); stdcall;external 'MouseHook.dll';  implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
    //
      FIncrement := 0;
      SetHook;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      //
      DelHook;
    end;procedure TForm1.FormShow(Sender: TObject);
    begin
      RegisterHandle(Self.Handle);
    end;procedure TForm1.WMMouseMsg(var Msg: TMessage);
    begin
      FIncrement := 0;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      Inc(FIncrement);
      if FIncrement > 60 then
        ShowMessage('超过1分钟未动鼠标!');
    end;
      

  3.   

    楼上的搞的太复杂了吧,直接在程序创建的时候记录鼠标的坐标,再开个定时器判断鼠标位置是否变化就可以了,用GetCursorPos就可以实现。画圆用SetCursorPos实现。
      

  4.   

    用TIME不太准....还是开线程计时,或用媒体计时器(其它高精度计时器)的好.
      

  5.   

    timer就可以了,要精确就用线程。
    hook没必要,毕竟是在自己的应用程序上画的。
      

  6.   

    timer设置1分钟画圆
    mousemove里重新定时
      

  7.   

    procedure TRTPMSCfgMainfrm.定时器1(Sender: TObject);// 定时器可设定十分之一秒触发一次
    var
      vLastInputInfo: TLastInputInfo;
    begin
        vLastInputInfo.cbSize := SizeOf(vLastInputInfo);
        GetLastInputInfo(vLastInputInfo);
        if GetTickCount - vLastInputInfo.dwTime > 60000 then //超过一分钟
        begin
            //画圆
        end;
    end;