Interface
USES the
The Vcl. ExtCtrls System. Classes, Winapi. Windows, Winapi. Messages, Vcl. Forms, Vcl. Dialogs;
Type
Time to no action//keyboard, mouse response, triggering event
TNoActionResponse=class (TTimer)
Private
FOnTimer: TNotifyEvent;
FNum: Integer;
Protected
Procedure Timer; Override.
Public
The constructor Create (AOwner: TComponent); Override.
The destructor Destroy; Override.
Procedure AppMessageHandler (var Msg: TMsg; Var Handled: Boolean);
Published
//all of the attributes of the events are a kind of, rely on Windows message to perform, and all the news event names are defined, or define your own message also triggers the corresponding event
The property OnTimer: TNotifyEvent read FOnTimer write FOnTimer;
//run after a few time, triggering
The property Num: Integer read FNum write FNum default 1;
The end;
Procedure Register;
Implementation
Procedure TNoActionResponse. AppMessageHandler (var Msg: TMsg; Var Handled: Boolean);
The begin
If (Msg) message=WM_MOUSEMOVE) or (Msg) message=WM_KEYDOWN) then
The begin
//off to open, again the timing, the writing is not very good, is there a better way
Enabled:=False;
Enabled:=True;
The end;
The end;
The constructor TNoActionResponse. Create (AOwner: TComponent);
The begin
Inherited the Create (AOwner);
Application. The OnMessage:=AppMessageHandler;
The end;
Destructor TNoActionResponse. Destroy;
The begin
Inherited;
The end;
Procedure TNoActionResponse. The Timer;
The begin
FNum: FNum=1;
If (Assigned (FOnTimer)) and (FNum=0) then
FOnTimer (Self);
The end;
Procedure Register;
The begin
RegisterComponents (" test ", [TNoActionResponse]);
The end;
End.
This is nothing suddenly want to write a team, didn't write for so many years, have forgotten almost!
Demand is to write a time controls, within the prescribed period of time the keyboard, the mouse without any response or no movement, triggering event, such as watching players, within 3 according to the keyboard, the mouse nothing happened, what is automatically hide button,
After I finished the above components, installation testing have no reaction, I think it must be there to write wrong, so I ask you the reader
CodePudding user response:
Use win API GetLastInputInfoI use so:
The function IsKMActionByInterval (const SpaceTime: Integer) : Boolean;
Var
ALastInputInfo: TLastInputInfo;
The begin
Result:=False;
ALastInputInfo. CbSize:=SizeOf (aLastInputInfo);
If GetLastInputInfo (aLastInputInfo) then
The begin
If GetTickCount - aLastInputInfo. DwTime & gt; SpaceTime then
Result:=True;
The end;
The end;
CodePudding user response: