做一個專案,要求5分鐘內無操作自動跳回主界面,這就需要判斷整個表單的滑鼠時間(表單 有N個控制元件,還有web控制元件是沒有click事件的),請問如何全盤控制表單的滑鼠點擊事件,只要滑鼠一點擊就回應?
uj5u.com熱心網友回復:
全域滑鼠監控一大堆,搜索一下即可。uj5u.com熱心網友回復:
GetLastInputInfo Function--------------------------------------------------------------------------------
The GetLastInputInfo function retrieves the time of the last input event.
Syntax
BOOL GetLastInputInfo( PLASTINPUTINFO plii
);
Parameters
plii
[out] Pointer to a LASTINPUTINFO structure that receives the time of the last input event.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Remarks
This function is useful for input idle detection. However, GetLastInputInfo does not provide system-wide user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input information for only the session that invoked the function.
Function Information
Minimum DLL Version user32.dll
Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 2000
See Also
Keyboard Input, LASTINPUTINFO
--------------------------------------------------------------------------------
uj5u.com熱心網友回復:
#pragma comment(lib,"ntdll")
#pragma comment(lib,"user32")
#include <afxdisp.h>
#include <windows.h>
#include <winnt.h>
#include <stdio.h>
#include <memory.h>
typedef struct tagLASTINPUTINFO {
UINT cbSize;
DWORD dwTime;
} LASTINPUTINFO, * PLASTINPUTINFO;
extern "C" BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii);
LASTINPUTINFO lii;
BOOL r;
extern "C" NTSYSAPI NTAPI NtQuerySystemInformation(
IN UINT SystemInformationClass, // 資訊型別
OUT PVOID SystemInformation, // 緩沖指標
IN ULONG SystemInformationLength, // 緩沖的位元組大小
OUT PULONG ReturnLength OPTIONAL // 寫入緩沖的位元組數
);
//第一個引數是請求的資訊型別。這個引數可以有許多值。為了得到系統啟動時間,我們只用其中的一個值:SystemTimeInformation(3)。
//如果,第一個引數是SystemTimeInformation,則第二個引數必須是一個SYSTEM_TIME_INFORMATION結構指標。
typedef struct {
LARGE_INTEGER liKeBootTime;//系統被啟動的時間(以毫秒計)。
LARGE_INTEGER liKeSystemTime;
LARGE_INTEGER liExpTimeZoneBias;
ULONG uCurrentTimeZoneId;
DWORD dwReserved;
} SYSTEM_TIME_INFORMATION;
SYSTEM_TIME_INFORMATION sti;
ULONG rl;
FILETIME ft;
int main() {
lii.cbSize=sizeof(LASTINPUTINFO);
r=GetLastInputInfo(&lii);
if (r) {
// printf("OK to GetLastInputInfo:dwTime==%d ms\n",lii.dwTime);
NtQuerySystemInformation(3,&sti,sizeof(sti),&rl);//3==SystemTimeOfDayInformation
// printf("NtQuerySystemInformation(SystemTimeOfDayInformation,...) return liKeBootTime==%I64u ms\n",*((unsigned __int64 *)&sti.liKeBootTime)/10000ui64);
COleDateTime t;
COleDateTimeSpan ts();
CString s,fmt;
fmt="%Y-%m-%d %H:%M:%S";
memcpy(&ft,&sti.liKeBootTime,8);
t=COleDateTime(ft);
s=t.Format(fmt);
printf(" BootDateTime: %s\n",s);
*((unsigned __int64 *)&ft)+=(unsigned __int64)(lii.dwTime)*10000ui64;
t=COleDateTime(ft);
s=t.Format(fmt);
printf("LastInputDateTime: %s\n",s);
} else {
printf("Fail to GetLastInputInfo!\n");
return 1;
}
return 0;
}
// BootDateTime: 2014-04-15 09:04:18
//LastInputDateTime: 2014-04-15 17:26:37
//
uj5u.com熱心網友回復:
GetLastInputInfoWM_SETFOCUS
WM_KILLFOCUS
這3組合一下完美解決...
思路, 前臺視窗根據 setfoucus 檢測是否視窗具有焦點,如果有則啟動計時器 5分鐘內 getlastinputinfo 檢測確認輸入說明有操作,反之則無
killfocus 時,啟動計時器5分鐘內setfocus 沒有接到焦點重新捕捉則直接視為超時即可, 反之將操作權交給setfocus即可
uj5u.com熱心網友回復:
子類化可以不?5分鐘沒有收到滑鼠,鍵盤訊息就、、
uj5u.com熱心網友回復:
覺得可能還是用GetLastInputInfo較合適一些,估計不需要那么高的權限。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/122845.html
標籤:VB基礎類
