User Idle Detection - c++

i want to detect User Idle Detection in c++
i used this winapi:
LASTINPUTINFO last_input;
last_input.cbSize = sizeof(LASTINPUTINFO);
last_input.dwTime = 0;
GetLastInputInfo(&last_input)
this methods work correctly with user Input like (mouse and keyboard),
but when i watch a movie this methods return wrong tickcount
i want right like "windows screen Saver" that detect user activity like (watch movie,mouse and keyboard) perfectly
how i can do this
thx

If you want to detect user idle, actually no user input, no display required, you can determines whether a screen saver is currently running using SPI_GETSCREENSAVERRUNNING.
If you want to get time period of user idle, you can see the last user input time as starting point and the time screen saver starts running as end point. Time difference between them is what you want.
More references: "System Sleep Criteria", "SystemParametersInfo()".

Related

How to receive Key Event from other App? [C++. Windows.h.]

I'm making a macro program that drags and drops and comebacks to drag-starting point process.
I designed it to work like this:
"MyMacro" is my program.
"3DMax" is an app I'm using.
(RC) is "Ctrl+Spacebar + Right click" input to setup drop-point.
(LC) is "Ctrl+Spacebar + Left click" input to activate the macro.
In "3DMax", I do (RC) on trash-can.
By doing (RC), my computer sends the cursor position information to "MyMacro".
That information is drop-point.
In "3DMax", I do (LC) on a unnecessary 3D Object.
By doing (LC), my computer sends CURRENT Cursor Position to "MyMacro".
That information is original-point. And then it runs macro which is "Hold Left Click - Move cursor to drop-point - Release Left Click - Comeback to original-point".
I just learned WM_KEYDOWN, but it doesn't run the event when "MyMacro" is not activating. I want this program to function even when it's minimalized.
I learned how to SEND keyinput to other program, but I don't know how to REICEVE keyinput from other program.
How can "MyMacro" get keyinput from other program so that it gets information without activating the window?
I don't expect to get full code for this, I just want to know the keyword that I can search and look deeper. Please help.

User input timer

I'm making a text-based game. I'm trying to have a little "health bar". When the user hit space, and when the button is pressed it will make health go up by 5, but while this is also happening I need something to be running in the background that is doing the same as if it was a AI, except I want it to subtract 1 every time and for it to only hit it once every second.
I tried getch(); the most but the problem with that is that it stops everything and waits for the user to use a input so nothing can be going on in the background that is subtracting health.
If you could use the _getch(); command in any way to accomplish this, because I already know how to use it well.

How to tell if win32 c++ application lost focus after CTRL-ALT-DEL?

I've written a win32 App in C++ (a game) and I want to be able to know if the application has lost focus due to the user pressing CTRL-ALT-DEL and starting the task manager. How can I do this? What I want to do after detecting the event is to minimize the window of my game and pause its processing (animations, audio, etc.). However, if the user returns from the CTRL-ALT-DEL menu to the game then it should keep running as usual. I've thought that I could check for key presses on CTRL, ALT and DEL but that doesn't seem to work and just reacting to the lost the focus (WM_KILLFOCUS) is not what I want.
You can use WTSRegisterSessionNotification(), you'll get the WM_WTSSESSION_CHANGE message when the user presses Ctrl+Alt+Del and switches to the secure desktop.
Beware that you cannot tell that it was actually the secure desktop that he switched to, that would be rather nasty security leak. You'll also get the notification when he switches to another logon session. Also a case where you want to stop your game of course.
For that matter, a game ought to automatically pause whenever the game window loses the foreground. Nobody likes to be killed when they switch to their email reader :) Use the WM_ACTIVATEAPP message

WinAPI: Trackbar scroll begin notification

I have a trackbar control in my app and I want to do something when user starts scroll operation (when he clicks on the trackbar's thumb). Since WM_HSCROLL doesn't notify about such event, I was wondering how do I get to know when user starts scrolling. I'd like to avoid processing SB_THUMBTRACK request since thay would mean I'd have to process it all the time when user's scrolling, and I just want to know when he starts doing it.
Just process TB_THUMBTRACK and ignore all subsequent TB_THUMBTRACKs until you get TB_ENDTRACK. That's roughly 5-9 lines of code.
For trackbars you also should use the TB_* (trackbar) constants and not the SB_* (scrollbar) constants even if their respective values are the same (e.g. SB_ENDSCROLL == TB_ENDTRACK == 8, SB_THUMBPOSITION == TB_THUMBPOSITION == 4).

Application not starting until form is displayed to user for the first time

This is a weird question. I have written a .NET application that starts a process. This process is a MFC application written in c++. For some reason the process does not start doing anything until the form is displayed to the user for the first time. For example, if the process starts minimized I have to un-minimize it (click on it) before it will start doing whatever it's supposed to do. Also, if my application is running and starting this process while the screen is locked the process behaves the same as if it's minimized. It doesn't start doing anything until I unlock the screen and it is displayed to the user for the first time. Like I said, this is a weird question so I hope I'm conveying the problem properly.
Sounds like your functionality is embedded in MFC Windows' load event. If you want the application to be more reactive, move that code to your application class.