-
March 5th, 2006, 07:56 PM
#1
::GetLastInputInfo (..)
I'm having trouble understanding how to properly use this function, most likely since my course hasn't covered data structures or pointers yet, but I'm very interested in learning.
The Function reads as:
Code:
BOOL GetLastInputInfo(
PLASTINPUTINFO plii
);
Parameters: plii, Pointer to a LASTINPUTINFO structure that receives the time of the last input event
Data Structure reads as:
Code:
typedef struct tagLASTINPUTINFO {
UINT cbSize;
DWORD dwTime;
} LASTINPUTINFO, *PLASTINPUTINFO;
Members: cbSize, Must be set to sizeof(LASTINPUTINFO).
dwTime, Tick count when the last input event was received.
As for the tick count... I checked MSDN and got
Code:
DWORD GetTickCount(void);
Though, this retrieves the time in milliseconds since the system was started, not from last input event. Anywho, I am thoroughly confused!
And would REAAAAALLY appreciate some help
-
March 5th, 2006, 08:01 PM
#2
Re: ::GetLastInputInfo (..)
You can do something like this:
Code:
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&lpi))
{
// failed, use GetLastError to get error code
}
// lpi.dwTime now holds the tick count when last input was made
- petter
-
March 5th, 2006, 08:25 PM
#3
Re: ::GetLastInputInfo (..)
Alright thanks, wildfrog.
This is my code as is, now (not very complex as im just trying to get the understanding of the getlastinputinfo function)
Code:
#include <windows.h>
#include <iostream>
using namespace std;
typedef struct tagLASTINPUTINFO {
UINT cbSize;
DWORD dwTime;
} LASTINPUTINFO, *PLASTINPUTINFO;
int main()
{
int enter;
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&lpi))
{
// failed, use GetLastError to get error code
}
// lpi.dwTime now holds the tick count when last input was made
cout << "enter 1: ";
cin >> enter;
if (enter==1){
cout << lpi.dwTime << endl;
}
return 0;
}
I get 1 error when compiling though:
error C2065: 'GetLastInputInfo' : undeclared identifier
:/
-
March 5th, 2006, 08:44 PM
#4
Re: ::GetLastInputInfo (..)
Read GetLastInputInfo.
You need to set up target platform (GetLastInputInfo needs Win2K):
Code:
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include <windows.h>
For more read Using the Windows Headers.
Then you also need to tell the linker to link User32.lib, you can either do that through the project setting or add this line to your code:
Code:
#pragma comment(lib, "user32.lib")
And, the LASTINPUTINFO structure is already defined (in winuser.h included in windows.h) so you shouldn't define it yourself.
- petter
-
March 5th, 2006, 08:46 PM
#5
Re: ::GetLastInputInfo (..)
Thanks for clearing that up for me, I REALLY appreciate it.
Question though, since you said GetLastInputInfo needs win2k, which operating systems would that make this obsolete for?
-
March 5th, 2006, 08:53 PM
#6
Re: ::GetLastInputInfo (..)
alright...sorry...another question :-/
I implemented the changes you pointed out, and it compiled and ran fine
heres the code
Code:
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include <windows.h>
#include <iostream>
#pragma comment(lib, "user32.lib")
using namespace std;
int main()
{
int enter;
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&lpi))
{
// failed, use GetLastError to get error code
}
// lpi.dwTime now holds the tick count when last input was made
cout << "enter 1: ";
cin >> enter;
if (enter==1){
cout << lpi.dwTime << endl;
}
return 0;
}
except lpi.dwTime returned the value of 609977562
which really puzzles me
-
March 5th, 2006, 08:59 PM
#7
Re: ::GetLastInputInfo (..)
Question though, since you said GetLastInputInfo needs win2k, which operating systems would that make this obsolete for?
You should be able to figure that out by looking at the 'Using the Windows Headers' link in my previous post.
Anyway, as far as I can see it won't work on these platforms:
Windows NT 4.0 (and previous)
Windows 98
Windows 95
But should work on :
Windows 2000
Windows XP
Windows Server 2003
Windows Vista
Windows Server "Longhorn"
except lpi.dwTime returned the value of 609977562
which really puzzles me
Compare that value to what you get from GetTickCount(). Their difference is the timespan (in ms) since last the input.
- petter
-
March 5th, 2006, 09:12 PM
#8
Re: ::GetLastInputInfo (..)
Yes, sorry about my question reguarding the obsolete operating systems, it was uncalled for, anywho.
updated code reads as:
Code:
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include <windows.h>
#include <iostream>
#pragma comment(lib, "user32.lib")
using namespace std;
int main()
{
double tickCount;
double idleCount;
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(LASTINPUTINFO);
if (!GetLastInputInfo(&lpi))
{
// failed, use GetLastError to get error code
}
// lpi.dwTime now holds the tick count when last input was made
cout << lpi.dwTime << endl;
tickCount = GetTickCount();
idleCount = ( lpi.dwTime - tickCount );
cout << idleCount << endl;
return 0;
}
first displays the lpi.dwTime, which returns 611282093
then displays idleCount, which is the difference between lpi.dwTime and GetTickCount().
Seems weird to me though, the results that it has returned for idleCount have ranged from -234 to 0.
Is this because I was last idle zero seconds ago, if that's the case the negatives confuse me ;o
*Edit*
Also, you put a comment that says "// lpi.dwTime now holds the tick count when last input was made" but then said I had to get the difference, so what value is lpi.dwTime holding?
Last edited by 80Degrees; March 5th, 2006 at 09:14 PM.
-
March 5th, 2006, 09:19 PM
#9
Re: ::GetLastInputInfo (..)
so what value is lpi.dwTime holding?
It hold the number of ticks (ms) since the computer was last restarted until the last input was made. And GetTickCount return the number of ticks from the computer was last restarted and until now.
It seems that you've swapped the two around. You call GetTickCount after GetLastInputInfo so GetTickCount will produce a higher tick count, as a result you'll get a number <= 0.
- petter
-
March 5th, 2006, 09:28 PM
#10
Re: ::GetLastInputInfo (..)
It seems that you've swapped the two around. You call GetTickCount after GetLastInputInfo so GetTickCount will produce a higher tick count, as a result you'll get a number <= 0.
Hmm.. I'm looking through my code and I'm not sure where I have them misordered, do you mean in the subtraction? Cause otherwise it seems that I have GetTickCount after GetLastInputInfo...atleast I think, ugh, I'm sorry for all the questions
-
March 5th, 2006, 09:29 PM
#11
Re: ::GetLastInputInfo (..)
The subtraction, yes.
- petter
-
March 5th, 2006, 09:41 PM
#12
Re: ::GetLastInputInfo (..)
   
Ok after swapping them, it came back with 1538 which is perfect since its in milliseconds / 1000 so I last made some input 1.5 seconds ago, which seems about right.
Last last last last last last, LAST question 
Does the GetLastInputInfo check for any sort of input, including mouse click, mouse movement, keyboard click?
-
March 6th, 2006, 01:58 AM
#13
Re: ::GetLastInputInfo (..)
@80Degrees please don’t post the same question on different threads you already asked it here.
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|