GetLastInputInfo changes with no input - winapi

I'm using GetLastInputInfo to track user idle time in a desktop mixed mode C++ / C# application.
On one user's machine, GetLastInputInfo will advance its time, even when I register no low level keyboard or mouse input via this method.
The user (a coworker so I have access to the machine) runs Windows 10 on a Lenovo Yoga.
Below is sample output from my program to poll on GetLastInputInfo and display low level mouse and keyboard events:
Mouse: 57 wParam:512 flags:0 pt:1366,57 14750640 12:06:37.0864968
Mouse: 58 wParam:512 flags:0 pt:1366,60 14750656 12:06:37.0964981
Mouse: 59 wParam:512 flags:0 pt:1365,60 14750671 12:06:37.1064994
GetLastInputInfo 60 gliiRet:True cbSize:8 dwTime:14750671 12:06:37.2465354
GetLastInputInfo 61 gliiRet:True cbSize:8 dwTime:15063750 12:11:50.2038808
which implies that mouse events at 12:06:37.1064994 caused GetLastInputInfo #60 at 12:06:37.2465354, but between 12:06:37.2465354 and 12:11:50.2038808, no mouse or keyboard user input events occurred, but still GetLastInputInfo advanced to a new dwTime.
I'd like to determine the root cause of this problem. Is this a faulty device driver? Are there other trappable user input events that affect GetLastInputInfo that I'm missing?
Thanks.

Related

Is a Gdk::ModifierType computer dependent?

I can capture Gdk::ModifierType. When I do mouse button events the modifier emits
272 for a left click
1040 for a right click
16 for a button release
If I run my program on another computer will it emit the same signals for mouse events?

Detecting CGAssociateMouseAndMouseCursorPosition

We're making a user-space device driver for OS X that moves the cursor using Quartz Events, and we ran into a problem when games — especially ones that run in a windowed mode — can't properly capture the mouse pointer (= contain/keep it within the boundaries of their windows). For example, it would go outside the game window and click on the desktop or nearby inactive applications.
We could fix this if only we could detect when an active application calls CGAssociateMouseAndMouseCursorPosition.
How would you do this? Any ideas are appreciated.
I dont know if this can help you
There is an option called Focus Follows Mouse
Focus Follows Mouse - The Mouse pointer will grab automatically change focus to a new window inisde this one app if you mouse over it, instead of having to click a window to get focus, then clicking to do something.
http://wineskin.urgesoftware.com/tiki-index.php?page=Manual+4.6+Advanced+-+Options
I have written a few different mouse logical layers (for bridging different input devices, etc.). I have found that hooking into the OS level WM_INPUT event is a sure way of getting very real-time mouse position information. There is also a less rigorous solution of just polling the mouse data you need from one of Windows' very primitive DLLs. They are lightning fast. You could poll on a 10ms timer and never see performance loss on a modern machine.

Is any one aware of windows event to trap the mouse and keyboard input

I want to trap windows mouse and keyboard input with the help of event given by windows for detecting system idle or not in C++.
Two things I have tried:
1. Hooking concept, but as antivirus might not allow it and also CPU usage increases if we use hooking.
2. GetLastInputInfo() which also eats CPU usage about 50 %
Anyone can tell me if windows event to trap the mouse and keyboard input is available or not...
You're not going to do any better than SetWindowsHookEx and WH_KEYBOARD & WH_MOUSE. The documentation for MouseProc & KeyboardProc will be handy as well.

wxPython - Trapping Mouse & Keyboard Events without window Focus

I am attempting to write a time management tool with wxPython that is ideally non-obtrusive and very much out of the way. The app so far can be used normally and minimized to the system tray for the duration of its use.
However, I notice that once the frame is not in focus, as it is when its 'Iconized', the mouse and keyboard trapping that normally works when the frame/app is in focus no longer works.
I am aware that I could write a C++ program to create a Message Queue Hook and trap all mouse and keyboard events at the OS level, but Id rather not roll up my sleeves that far. After all trying to avoid getting my hands that dirty is why I am writing the UI in wxPython in the first place :)
Do you really need mouse and keyboard events or would it be sufficient to just know if the user has been idle? (You mentioned a time management app, so this seems feasible.)
This code will work on Windows and returns the idle time in seconds.
from ctypes import Structure, windll, c_uint, sizeof, byref
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_uint),
]
def get_idle_duration():
lastInputInfo = LASTINPUTINFO()
lastInputInfo.cbSize = sizeof(lastInputInfo)
windll.user32.GetLastInputInfo(byref(lastInputInfo))
millis = windll.kernel32.GetTickCount() - lastInputInfo.dwTime
return millis / 1000.0

Setting Virtual Key/MouseButton State Without Triggering Events

Is it possible to set the virtual key state / mouse button state for all programs on a computer without triggering the associated events at the same time (like setting the left mouse button to be currently pressed without sending a mouse down event). Could this be achieved by setting up a fake keyboard or mouse driver for a fake keyboard or mouse that when queried as to the current state of a key would reply giving an answer of your choice or by any other means?
Edit:
This has to affect programs that I do not have the code for running in other threads ect...
Well, I don't have a complete answer for you but...
The Win32 function SetKeyboard State() changes the state of the keyboard for the thread that called it.
I know this does not affect the entire system, but if you only need the keyboard state changed for applications you are developing, then this could be called by each program, reading in the array passed to it from a temporary file on the harddrive.
Otherwise... don't know of anything else offhand...

Resources