I wrote a (very small) program that lost a certain Bluetooth connection, for a few seconds for user inactivity Should wait and lock any system when there is no activity.
I do not need to detect cross-session, but it should be global within session (i.e., not only input from current process).
I would be happy if there could be a simple, reliable solution. In particular, I want to avoid global hooks.
My first attempt was to use in the beginning:
LASTINPUTINFO lii; Lii.dwSize = sizeof (LASTINPUTINFO); GetLastInputInfo (& amp; LII); G_iLastActivity = lii.dwTime;
Then, I set a timer and WM_TIMER
LASTINPUTINFO lii; Lii.dwSize = sizeof (LASTINPUTINFO); GetLastInputInfo (& amp; LII); If (lii.dwTime & gt; g_iLastActivity) LockWorkStation (); Unfortunately, this does not seem reliable. Although I do not touch anything at all, the second call often provides a big value. My next attempt is raw input when my main window is created, then I do:
Rauvenpub DewS Reid [2]; Ridge [0] .usUsagePage = 0x01; Ridge [0] .usUsage = 0x02; Ridge [0] .dwFlags = RIDEV_NOLEGACY; Ridge [0]. HwndTarget = hWnd; Ridge [1] .usUsagePage = 0x01; Ridge [1] .usUsage = 0x06; Ridge [1] .dwFlags = RIDEV_NOLEGACY; Ridge [1]. HwndTarget = hWnd; If (Registered Rivineput Devices (Reid, 2, Psychofe (Ridge [0])) == FALSE- Return;
Again, I set a timer for my timeout and I have WM_INPUT:
Case WM_INPUT: KillTimer (hWnd, IDTIMER); // End your app brake;
and in WM_TIMER:
WM_TIMER: break (wParam! = IDTIMER); LockWorkStation (); KillTimer (hWnd, IDTIMER); // End your app brake;
Unfortunately it is not reliable or not. Even here, in some cases I get WM_INPUT completely, although there is no user input. In other cases, I do not get any WM_INPUT. It seems that this happens when my application does not focus (i.e., it does not work globally).
I found some articles (for example), but ultimately they all point out GetLastInputInfo which does not seem to be reliable work for me.
Is this view wrong? If so, why? If not, what is the easiest way to do this?
No comments:
Post a Comment