Auto switching between windows in VisualBasic

August 11, 2011 at 21:29:49
Specs: Windows XP
Hi all,
I've never written VB script and was wondering if someone could show me a sample script that does this:
Monitors mouse and/or keyboard and if there was no input for 10 seconds it starts switching between all open windows (I'm guessing SendKeys ALT+TABTAB command) every 5 seconds. If it detects mouse/keyboard activity it hibernated until 10 second after last input and resumed switching again.
Thanks in advance!

P.S. I know there is tons of automation software out there that could do this, however that is not what I need. Don't want to install a dedicated software package for something that could be done in probably 30 lines of code.



See More: Auto switching between windows in VisualBasic

Report •


#1
August 12, 2011 at 06:49:03
I do not know of any way for VBScript to track user activity. Sorry.

How To Ask Questions The Smart Way


Report •

#2
August 12, 2011 at 12:16:27
What language can be used to determine if there is HID activity? If it's not possible with VB I'm open to other languages, I guess the criteria is the language has to be supported by XP without having to install any packages.

I know that in a lot of programs (such as AV, updaters etc) you can set it where it would only start process if the computer is idle. This seems to me to be pretty much same thing, except my idle state would be considered after 10 seconds...

Razor,
I guess for now I would be happy to see VB script to just switch between windows whenever you run the script. Thanks.



Report •

#3
August 12, 2011 at 15:15:23
I know that in a lot of programs (such as AV, updaters etc) you can set it where it would only start process if the computer is idle.
There's a few ways to do that. You could hook WH_SYSMSGFILTER and watch for the screen saver activation message. (This assumes the screen saver is enabled.) You could hook WH_FOREGROUNDIDLE, and detect idle situations that way. Hooks in general should be in a language with low overhead and high speed. C's the preferred language.

In your case, you'd probably use GetLastInputInfo(), since your program / script never sleeps. This requires a language that can interface with the Win32 API, however. C is the default language for these problems, but you could use VBA or PowerShell (if either are installed). Batch and VBScript are out, though. Other languages are possible, but like VBA / PS, most of them need to be installed on the host PC first.

I guess for now I would be happy to see VB script to just switch between windows whenever you run the script.
I do not know of any way for VBScript to switch window focus / change window z-level. Sorry. (Before you ask, sending Alt-Tab does nothing.)

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
August 12, 2011 at 23:58:25
Razor,
Thanks for clarification and references. Made me realize how little I understand about Windows and programming languages so I went out and read up a little more. So C it is (because of native XP support). What scares me is that C is pretty low level language and might be more that I can handle (I took BASIC in HS and that's about it).
I'm trying to put this thing together in next few days but not sure if it's realistic. It does look that my scenario GetLastInputInfo() command is the way to go, I saw a code for displaying time from last HID input, will try to patch it together. But hey if anyone has time and desire to help me with this I would appreciate it :)

Report •


Ask Question