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

System UDFs

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

Monitor Keyboard and Mouse UDF


The WaitForIdle UDF is designed to suspend the script until no keyboard and mouse movements occur within a certain time period. For example, say you want a script that waits until the system has been idle for 30 minutes, then does something. This is the code to accomplish this.
#definefunction GetKeyboardState(buf)
	sDLLName = StrCat(DirWindows(1), "user32.dll")
	DLLCall(sDLLName, long:"GetKeyboardState", lpbinary:buf)
	BinaryEodSet(buf, 256) 
	return buf
#endfunction

#DefineFunction WaitForIdle(time)
	BoxOpen("Check if System is Idle","Initializing")
	While @True
		IntControl(80,0,0,0,0);wait til no keys are pressed
		statusflag = 0 
	
		;Check mouse
		currcoordinates = MouseInfo(2)
		coordinates = currcoordinates
	
		;Check keyboard
		currbuf = BinaryAlloc(256)
		newbuf = BinaryAlloc(256)
		currkbstate = GetKeyboardState(currbuf)
		kbstate = currkbstate 
	
		count = 0
		While coordinates == currcoordinates && BinaryCompare(currkbstate, 0, kbstate, 0, 256)
		  count = count+1
		  BoxText(count)
		  if count == time
			  statusflag = 1
			  break
		  endif
		  timedelay(1); check every second
		  currcoordinates = MouseInfo(2)
		  kbstate = GetKeyboardState(newbuf)
		EndWhile

		BinaryFree(currbuf)
		BinaryFree(newbuf)
	
		if statusflag == 1
		  return 1
		endif
	EndWhile
#EndFunction

time = 1800 ; 30 minutes
WaitForIdle(time)
Pause("Workstation",StrCat("Has been Idle for ",time," seconds"))

Article ID:   W16234
File Created: 2004:03:30:15:43:32
Last Updated: 2004:03:30:15:43:32