GetLastInputTime help

  • Follow


I am starting a project that will shut down Firefox if there is no
keyboard or mouse activity for
5 minutes or more.

I am starting with learning how to use the GetLastInputTime API.

I know I have to fill the LASTINPUTINFO first.

Doing a goggle and bing search gave me some material, but in languages
quite different
than assembly.

Four assembly boards had even less material.

It looks like the API could be used for a lot of things.

Could someone get me started?

Thanks,

Andy



0
Reply Andy 11/18/2010 12:06:05 AM

On Nov 17, 7:06=A0pm, Andy <chocolatemint77...@nospicedham.yahoo.com>
wrote:
> I am starting a project that will shut down Firefox if there is no
> keyboard or mouse activity for
> 5 minutes or more.
>
> I am starting with learning how to use the GetLastInputTime API.
>
> I know I have to fill the LASTINPUTINFO first.
>
> Doing a goggle and bing search gave me some material, but in languages
> quite different
> than assembly.
>
> Four assembly boards had even less material.
>
> It looks like the API could be used for a lot of things.
>
> Could someone get me started?
>

Ha!  Yeah, right!

http://msdn.microsoft.com/en-us/library/dd919985%28v=3DVS.85%29.aspx

That obviously isn't a standard Windows API function.  It looks like
Object-Oriented .NET stuff.  All of your hair will fall out if you
attempt to make calls to any of those methods from a simple ASM
program.  But if you DO (by some magical miracle) figure it out,
please let the rest of us know.

Nathan.

0
Reply Nathan 11/18/2010 1:52:40 AM


On Nov 17, 7:52=A0pm, Nathan <nathancba...@gmail.com> wrote:
> On Nov 17, 7:06=A0pm, Andy <chocolatemint77...@nospicedham.yahoo.com>
> wrote:
>
>
>
> > I am starting a project that will shut down Firefox if there is no
> > keyboard or mouse activity for
> > 5 minutes or more.
>
> > I am starting with learning how to use the GetLastInputTime API.
>
> > I know I have to fill the LASTINPUTINFO first.
>
> > Doing a goggle and bing search gave me some material, but in languages
> > quite different
> > than assembly.
>
> > Four assembly boards had even less material.
>
> > It looks like the API could be used for a lot of things.
>
> > Could someone get me started?
>
> Ha! =A0Yeah, right!
>
> http://msdn.microsoft.com/en-us/library/dd919985%28v=3DVS.85%29.aspx
>
> That obviously isn't a standard Windows API function. =A0It looks like
> Object-Oriented .NET stuff. =A0All of your hair will fall out if you
> attempt to make calls to any of those methods from a simple ASM
> program. =A0But if you DO (by some magical miracle) figure it out,
> please let the rest of us know.
>
> Nathan.

Sorry, I am very sore and mentally tired.

I've spent the week job hunting - all of it cold-calling.

It should have been ->

GetLastInputInfo Function

Retrieves the time of the last input event.
Syntax
Copy

BOOL WINAPI GetLastInputInfo(
  __out  PLASTINPUTINFO plii
);

Parameters

plii [out]
    PLASTINPUTINFO

    A pointer to a LASTINPUTINFO structure that receives the time of
the last input event.

Return Value

BOOL

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.
0
Reply Andy 11/18/2010 3:24:12 AM

Oh, you mean this: 
http://msdn.microsoft.com/en-us/library/ms646302%28VS.85%29.aspx

.....in that case...   using NASMX, I'd start with something like this:

%include '..\..\..\inc\nasmx.inc'
%include '..\..\..\inc\win32\windows.inc'
%include '..\..\..\inc\win32\kernel32.inc'
%include '..\..\..\inc\win32\user32.inc'

STRUC LASTINPUTINFO
...cbSize resd 1
...dwTime resd 1
ENDSTRUC

IMPORT GetLastInputInfo, 4

.....

[section .data]
plii istruc LASTINPUTINFO
 at LASTINPUTINFO.cbSize, dd 8
 at LASTINPUTINFO.dwTime, dd 0
iend

[section .text]
.....
invoke GetLastInputInfo, plii
.....

or without using the 'invoke' macro...

pushd plii
call GetLastInputInfo

.....

Also, in that "ActivityMonitoring" example, notice that we don't need this 
line:

lastInPut.cbSize = 
(uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);...because we 
already know the size of the structure.Nathan. 


0
Reply Nathan 11/18/2010 4:16:24 AM

On Nov 18, 1:52=A0am, Nathan <nathancba...@gmail.com> wrote:
> That obviously isn't a standard Windows API function. =A0It looks like
> Object-Oriented .NET stuff. =A0All of your hair will fall out if you
> attempt to make calls to any of those methods from a simple ASM
> program. =A0But if you DO (by some magical miracle) figure it out,
> please let the rest of us know.

OK, so it turns out that in this case calling an Object Method wasn't
required.  But IMHO it's misleading to suggest that doing so from asm
is difficult.  The Microsoft header files invariably give a plain C-
style interface to these methods as well as the C++ variety; look for
a conditional clause which starts:

#else    /* C style interface */

That's certainly true for the function you referred to
(IWTSProtocolConnection::GetLastInputTime).  It's declared in the file
'wtsprotocol.h' and the Vtable layout is detailed there under:

typedef struct IWTSProtocolConnectionVtbl

So with that information it's quite straightforward to call it from
assembler code.

Richard.
http://www.rtrussell.co.uk/

0
Reply Richard 11/18/2010 6:52:55 PM

But how do we link the .NET Virtual Machine into our code??  Which DLL do we 
link against?  Is there a "dotnetvm.dll"?

Also, calling a 'method' infers that we need to reference (or instantiate) 
an object.  Don't we need a 'this' pointer?  Do we need to construct a 
little bit of scaffolding in CIL [MSIL] to handle these details?  Or does 
the C-interface stuff you mentioned handle the scaffolding for us?

Wouldn't the .NET VM block access from our code on the grounds that our code 
breaks major tenets of "Managed Code" philosophy?  Security, etc...

Nathan.


0
Reply Nathan 11/18/2010 8:33:30 PM

On Nov 18, 8:33=A0pm, "Nathan Baker"
<nathancba...@nospicedham.gmail.com> wrote:
> But how do we link the .NET Virtual Machine into our code?? =A0Which DLL =
do we
> link against? =A0Is there a "dotnetvm.dll"?

I see nothing to imply that the IWTSProtocolConnection Interface is
specifically a .NET interface; it appears to be an ordinary COM
interface as far as I understand the docs.

> Also, calling a 'method' infers that we need to reference (or instantiate=
)
> an object. =A0Don't we need a 'this' pointer?

Yes, but that's often no more difficult than calling (for example)
CoCreateInstance in OLE32.DLL.

> Wouldn't the .NET VM block access from our code on the grounds that our c=
ode
> breaks major tenets of "Managed Code" philosophy? =A0Security, etc...

Calling Object Methods and interfacing with Managed Code are different
things.  It may well be difficult to access Managed Code from
assembler (I've never tried) but calling COM Object Methods isn't.

Richard.
http://www.rtrussell.co.uk/
0
Reply Richard 11/18/2010 10:07:17 PM

On Nov 18, 4:07=A0pm, Richard Russell <n...@nospicedham.rtrussell.co.uk>
wrote:
> On Nov 18, 8:33=A0pm, "Nathan Baker"
>
> <nathancba...@nospicedham.gmail.com> wrote:
> > But how do we link the .NET Virtual Machine into our code?? =A0Which DL=
L do we
> > link against? =A0Is there a "dotnetvm.dll"?
>
> I see nothing to imply that the IWTSProtocolConnection Interface is
> specifically a .NET interface; it appears to be an ordinary COM
> interface as far as I understand the docs.
>
> > Also, calling a 'method' infers that we need to reference (or instantia=
te)
> > an object. =A0Don't we need a 'this' pointer?
>
> Yes, but that's often no more difficult than calling (for example)
> CoCreateInstance in OLE32.DLL.
>
> > Wouldn't the .NET VM block access from our code on the grounds that our=
 code
> > breaks major tenets of "Managed Code" philosophy? =A0Security, etc...
>
> Calling Object Methods and interfacing with Managed Code are different
> things. =A0It may well be difficult to access Managed Code from
> assembler (I've never tried) but calling COM Object Methods isn't.
>
> Richard.http://www.rtrussell.co.uk/

Someone was nice enough to write me some code.

It shows idle time, system uptime, and last input.

It shows system uptime and then zeros out whenever there is any "input
activity".(mouse or kb)

When there is input, last output starts incrementing.

Now, to figure out the next step, I have to subject the correct values
to determine when 5 minutes have gone by.

When that is done, I have been told that ->

<The window enumeration is really the only tricky part originally.>

I know how to stop a process.

I am studying the code when I have time.

Have a great day,
                          Andy

http://intouch.org/magazine/daily-devotional
http://www.happynews.com
0
Reply Andy 11/18/2010 11:11:46 PM

On Nov 18, 5:11=A0pm, Andy <chocolatemint77...@nospicedham.yahoo.com>
wrote:
> On Nov 18, 4:07=A0pm, Richard Russell <n...@nospicedham.rtrussell.co.uk>
> wrote:
>
>
>
> > On Nov 18, 8:33=A0pm, "Nathan Baker"
>
> > <nathancba...@nospicedham.gmail.com> wrote:
> > > But how do we link the .NET Virtual Machine into our code?? =A0Which =
DLL do we
> > > link against? =A0Is there a "dotnetvm.dll"?
>
> > I see nothing to imply that the IWTSProtocolConnection Interface is
> > specifically a .NET interface; it appears to be an ordinary COM
> > interface as far as I understand the docs.
>
> > > Also, calling a 'method' infers that we need to reference (or instant=
iate)
> > > an object. =A0Don't we need a 'this' pointer?
>
> > Yes, but that's often no more difficult than calling (for example)
> > CoCreateInstance in OLE32.DLL.
>
> > > Wouldn't the .NET VM block access from our code on the grounds that o=
ur code
> > > breaks major tenets of "Managed Code" philosophy? =A0Security, etc...
>
> > Calling Object Methods and interfacing with Managed Code are different
> > things. =A0It may well be difficult to access Managed Code from
> > assembler (I've never tried) but calling COM Object Methods isn't.
>
> > Richard.http://www.rtrussell.co.uk/
>
> Someone was nice enough to write me some code.
>
> It shows idle time, system uptime, and last input.
>
> It shows system uptime and then zeros out whenever there is any "input
> activity".(mouse or kb)
>
> When there is input, last output starts incrementing.
>
> Now, to figure out the next step, I have to subject the correct values
> to determine when 5 minutes have gone by.
>
> When that is done, I have been told that ->
>
> <The window enumeration is really the only tricky part originally.>
>
> I know how to stop a process.
>
> I am studying the code when I have time.
>
> Have a great day,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Andy
>
> http://intouch.org/magazine/daily-devotionalhttp://www.happynews.com

Here is some code. PLEASE leave credits in the source.

Thanks,
        Andy


; GetLastInputInfo.asm Code by MarMo as posted
; on http://www.winasm.net/forum/index.php

    .486
    .model flat, stdcall
    option casemap :none

    include \masm32\include\windows.inc
    include \masm32\include\user32.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\gdi32.inc
    include \masm32\macros\pomacros.asm

    includelib \masm32\lib\user32.lib
    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\gdi32.lib

    WinMain   		PROTO :DWORD,:DWORD,:DWORD,:DWORD
    WndProc   		PROTO :DWORD,:DWORD,:DWORD,:DWORD
    TopXY     		PROTO :DWORD,:DWORD
    Static
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
    SetStaticTxt   	PROTO :DWORD,:DWORD
    mTimerProc 		PROTO :DWORD,:DWORD,:DWORD,:DWORD

    LASTINPUTINFO	Struct
		cbSize		dd	?
		dwTime		dd	?
	LASTINPUTINFO	EndS

    .data
        szDisplayName db "GetLastInputInfo help",0

    .data?
        CommandLine   dd ?
        hWnd          dd ?
        hInstance     dd ?

    .code

start:
        invoke GetModuleHandle, NULL
        mov hInstance, eax

        invoke GetCommandLine
        mov CommandLine, eax

        invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
        invoke ExitProcess,eax

WinMain proc hInst     :DWORD,
             hPrevInst :DWORD,
             CmdLine   :DWORD,
             CmdShow   :DWORD

          ; LOCALs on stack

        LOCAL wc   :WNDCLASSEX
        LOCAL msg  :MSG

        LOCAL Wwd  :DWORD
        LOCAL Wht  :DWORD
        LOCAL Wtx  :DWORD
        LOCAL Wty  :DWORD

        ; Fill WNDCLASSEX structure with required variables

        mov wc.cbSize,         sizeof WNDCLASSEX
        mov wc.style,          CS_BYTEALIGNWINDOW
        mov wc.lpfnWndProc,    offset WndProc
        mov wc.cbClsExtra,     NULL
        mov wc.cbWndExtra,     NULL
        m2m wc.hInstance,      hInst
        mov wc.hbrBackground,  COLOR_BTNFACE+1
        mov wc.lpszMenuName,   NULL
        mov wc.lpszClassName,  offset szClassName
        mov wc.hIcon,          NULL
        invoke LoadCursor,NULL,IDC_ARROW
        mov wc.hCursor,        eax
        mov wc.hIconSm,        0

        invoke RegisterClassEx, ADDR wc

        ; Center window at following size

        mov Wwd, 300
        mov Wht, 110

        invoke GetSystemMetrics,SM_CXSCREEN
        invoke TopXY,Wwd,eax
        mov Wtx, eax

        invoke GetSystemMetrics,SM_CYSCREEN
        invoke TopXY,Wht,eax
        mov Wty, eax

        szText szClassName,"GetLastInputInfo_Class"

        invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,
                              ADDR szClassName,
                              ADDR szDisplayName,
                              WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN,
                              Wtx,Wty,Wwd,Wht,
                              NULL,NULL,
                              hInst,NULL
        mov   hWnd,eax

        invoke ShowWindow,hWnd,SW_SHOWNORMAL
        invoke UpdateWindow,hWnd

      ; Loop until PostQuitMessage is sent

    StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0
      cmp eax, 0
      je ExitLoop
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage,  ADDR msg
      jmp StartLoop
    ExitLoop:

      return msg.wParam

WinMain endp

WndProc proc hWin   :DWORD,
             uMsg   :DWORD,
             wParam :DWORD,
             lParam :DWORD

    LOCAL Rc      :RECT
    LOCAL rLeft   :DWORD
    LOCAL rTop    :DWORD
    LOCAL rRight  :DWORD
    LOCAL rBottom :DWORD

    .if uMsg =3D=3D WM_CREATE

      jmp @F
          lbl1 db "Idle Time:",0
          lbl2 db "System Uptime:",0
          lbl3 db "Last Input:",0
          lbl4 db "0 seconds ",0
      @@:

	  ;Create labels
      invoke Static,ADDR lbl1,hWin,20,5,130,18,-1,WS_CHILD or
WS_VISIBLE or SS_LEFT
      invoke Static,ADDR lbl2,hWin,20,30,130,18,-1,WS_CHILD or
WS_VISIBLE or SS_LEFT
      invoke Static,ADDR lbl3,hWin,20,55,130,18,-1,WS_CHILD or
WS_VISIBLE or SS_LEFT

      invoke Static,ADDR lbl4,hWin,130,5,140,18,500,WS_CHILD or
WS_VISIBLE or SS_RIGHT
      invoke Static,ADDR lbl4,hWin,130,30,140,18,501,WS_CHILD or
WS_VISIBLE or SS_RIGHT
      invoke Static,ADDR lbl4,hWin,130,55,140,18,502,WS_CHILD or
WS_VISIBLE or SS_RIGHT

      ; start timer proc 1000 =3D 1 secund
      invoke SetTimer,hWin,NULL,1000,addr mTimerProc

    .elseif uMsg =3D=3D WM_SIZE

    .elseif uMsg =3D=3D WM_CLOSE

    .elseif uMsg =3D=3D WM_DESTROY
        invoke PostQuitMessage,NULL
        return 0
    .endif

    invoke DefWindowProc,hWin,uMsg,wParam,lParam

    ret

WndProc endp

TopXY proc wDim:DWORD, sDim:DWORD

    shr sDim, 1      ; divide screen dimension by 2
    shr wDim, 1      ; divide window dimension by 2
    mov eax, wDim    ; copy window dimension into eax
    sub sDim, eax    ; sub half win dimension from half screen
dimension

    return sDim

TopXY endp

Static proc lpText:DWORD,hParent:DWORD,
=20
a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,ID:DWORD,dwStyle:DWORD

    LOCAL hStat   :DWORD
    LOCAL hFont   :DWORD

    szText statClass,"STATIC"

    invoke CreateWindowEx,WS_EX_STATICEDGE,
            ADDR statClass,lpText,
            dwStyle,
            a,b,wd,ht,hParent,ID,
            hInstance,NULL

    mov hStat, eax

    invoke GetStockObject,ANSI_FIXED_FONT
    mov hFont, eax
    invoke SendMessage,hStat,WM_SETFONT,hFont, 0

    mov eax, hStat

    ret

Static endp

SetStaticTxt proc TickCount :DWORD, ID :DWORD

    LOCAL Buffer[24]:BYTE

    xor edx, edx
    mov eax, TickCount
    mov ecx, 1000
    div ecx

    szText ctlstr,"%-2.6lu seconds "
    invoke wsprintf,ADDR Buffer,ADDR ctlstr,eax

    invoke SetDlgItemText,hWnd,ID,ADDR Buffer

    ret

SetStaticTxt endp

mTimerProc proc hWndT    :DWORD,
                uMsg     :DWORD,
                idEvent	 :DWORD,
                dwTime   :DWORD

    LOCAL plii			:LASTINPUTINFO
    LOCAL LastInputTicks  	:DWORD
	LOCAL IdleTicks 		:DWORD
	LOCAL systemUptime 	:DWORD

	;The tick at which the last input was recorded
	mov LastInputTicks, 0

	;The number of ticks that passed since last input
	mov IdleTicks, 0

	;Set the struct
	mov plii.cbSize, sizeof LASTINPUTINFO
	mov plii.dwTime, 0

	;If we have a value from the function

	invoke GetLastInputInfo, addr plii
	.If eax!=3D0
		;Get the number of ticks at the point when the last activity was
seen
		m2m LastInputTicks, plii.dwTime

		;Number of idle ticks =3D system uptime ticks - number of ticks at
last input
		invoke GetTickCount
		mov systemUptime, eax
		sub eax, LastInputTicks
		mov IdleTicks, eax
	.EndIf

	;change text

      invoke SetStaticTxt,systemUptime,500
	invoke SetStaticTxt,IdleTicks,501
	invoke SetStaticTxt,LastInputTicks,502

    ret

mTimerProc endp

end start
0
Reply Andy 11/19/2010 3:56:31 PM

8 Replies
195 Views

(page loaded in 0.151 seconds)

Similiar Articles:






7/12/2012 9:28:36 AM


Reply: