WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Internet time monitor


Question:

I'd like to be able to track/log what window is active and determine if there is mouse movement with negligable performance degredation. It seems having a looping WinBatch on even a polling cycle would be too much. Can you suggest any function or extender I should look into?

What I'm trying to do is write a little applet that trys to track the time spent browsing the Internet by incrementing a timer while a browser is the active window and there is mouse activity within a certain time threshhold...and yet not needlessly effect overall system performance.

Answer:

Here is some code which should fit your needs. Note: Winbatch is designed to be very UN-greedy when using processor time. I believe the following code should fit your needs.
IntControl(54,"",1,0,0)
timer = 0
BoxOpen("Internet Monitor",StrCat("Initializing....",@CRLF,@CRLF,"Hold the shift key down to exit")) while 1 ; timing loop (every 5 seconds)
   mouse=MouseInfo(2); Mouse coordinates, assuming a 1000x1000 virtual screen
   wnd=WinGetActive(); Gets the title of the active window.
	found = StrIndexNC (wnd, "Microsoft Internet Explorer", 1, @FWDSCAN)
   while found !=0; Detect loop
      if IsKeyDown(@SHIFT|@CTRL) then break ;Used to cancel script
      TimeDelay(1) ; Adjust resolution 
      timer=timer+1 ; Adjust here also
		BoxTitle(StrCat("Internet Monitor: Timer = ",timer))
		
		;Add mouse checking here
		mousenew=MouseInfo(2); Mouse coordinates, assuming a 1000x1000 virtual screen
		if mousenew != mouse
		   BoxText("Mouse has moved")
			TimeDelay(0.5)
		else
			BoxText("Mouse has not moved")
			TimeDelay(0.5)
		endif
		mouse = mousenew

		wnd=WinGetActive(); Gets the title of the active window.
	   found = StrIndexNC (wnd, "Microsoft Internet Explorer", 1, @FWDSCAN)
   endwhile
	BoxText("Microsoft Internet Explorer not activated")
   TimeDelay(1)
Endwhile

Article ID:   W15988
File Created: 2004:03:30:15:42:06
Last Updated: 2004:03:30:15:42:06