开发者

Cancel idle state by code…

开发者 https://www.devze.com 2023-03-09 10:58 出处:网络
I am detecting the machine Idle state and if Idle, I perform an action. One of the actions must be canceling this st开发者_运维技巧ate otherwise it will enter a loop.

I am detecting the machine Idle state and if Idle, I perform an action.

One of the actions must be canceling this st开发者_运维技巧ate otherwise it will enter a loop.

I want to prevent re-entry into my idle loop when I'm executing in it, how do I do this?


One way to prevent re-entrance is to memorize if you have entered the event handler:

type
  TForm1 = class(TForm)
    ApplicationEvents1: TApplicationEvents;
    procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
  private
    { Private-Deklarationen }
    FInOnIdle: Boolean;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
begin
  if FInOnIdle then Exit;

  FInOnIdle := True;
  try
    
  finally
    FInOnIdle := False;
  end;
end;


Add a flags in your form's vars that tests to see if you're already in an idle loop:

interface

type TForm1 = class(TForm)
...
private
...
  InIdleLoop: boolean;
...

implementation

procedure TForm1.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
begin
  if InIdleLoop then exit;
  InIdleLoop:= true
  try
   //Do your idle processing here

  finally
    InIdleLoop:= false;
  end; {try}
end;


By pressing a key i guess this will do the trick

  keybd_event(VK_SHIFT,MapVirtualKey(VK_SHIFT,0),0,0);
  keybd_event(VK_SHIFT,MapVirtualKey(VK_SHIFT,0),KEYEVENTF_KEYUP,0);

This presses the shiftkey and the system will think the computer isn't idle any more...

0

精彩评论

暂无评论...
验证码 换一张
取 消