Jeff
Fri Mar 07 12:26:49 CST 2008
Nope, never do that. Bad practice.
"Tom Lavedas" <tglbatch@cox.net> wrote in message
news:c3905aeb-b2fc-4d4c-baca-99981368e36b@m3g2000hsc.googlegroups.com...
> On Mar 6, 8:30 pm, "Jeff Dillon" <jeffdil...@hotmailremove.com> wrote:
>> Ouch! Never use SendKeys. It will send keys to the currently active
>> window,
>> which can change at any time, of course
>>
>> Jeff
>>
>> "Tom Lavedas" <tglba...@cox.net> wrote in message
>>
>> news:742b2426-49ed-4b3c-9885-df04f0f0cc51@m34g2000hsc.googlegroups.com...
>>
>> > On Mar 4, 1:42 pm, Blue Streak <rdlebre...@hotmail.com> wrote:
>> >> Hello,
>>
>> >> I am trying to develop a script that will adjust the master volume
>> >> control on a computer. The best example that I have been able to find
>> >> is the following:
>>
> {snip}
>> >> Is there something that like an ActiveX object or WMI control that I
>> >> can use instead where I can set the volume=10 or 10%?
>>
>> >> TIA...
>>
>> > It doesn't appear that the WMI Win32_SoundDevice class has any method
>> > to control the volume. According to MS documentation at MSDN, it only
>> > has two methods, Reset and SetPowerSomething. Neither of which
>> > provides any help.
>>
>> > In addition, SndVol32.exe only has two command line switches, -R to
>> > reset it into record mode and -D to ID a device and no arguments. So
>> > that's a bust, too.
>>
>> > The only thing I can offer is an improved version of your script ...
>>
>> > with CreateObject("Wscript.Shell")
>> > .Run "sndvol32"
>> > do until .AppActivate("Volume") : wsh.Sleep 50 : Loop
>> > .SendKeys "{TAB}{END}" : wsh.Sleep 50
>> > .SendKeys "{PGUP}" : wsh.Sleep 50
>> > .SendKeys "%{F4}" : wsh.Sleep 50
>> > end with
>>
>> > It will take a lot less than three seconds to function. I noted that
>> > on my XP machine sndvol32 opens a control panel with the title of
>> > "Master Volume", so I shortened the title to work with both your
>> > version and my version of the title. I also closed the loop around
>> > the AppActivate to make the process a little more robust.
>>
>> > Tom Lavedas
>> > ===========
>> >
http://members.cox.net/tglbatch/wsh/
>
> Though I understand your intent, "never" is a fighting word -
> especially when you offer no alternative.
>
> Yes, the keystrokes can go astray, but sometimes its still the most
> efficient way to do a little task for your own purposes. It probably
> should be avoided in any 'production' environment, but I still think
> there are a few simple tasks that can benefit from judicial use of
> Sendkeys.
>
> Clearly, the 'open-loop' examples generally given in the documentation
> are an abomination, but with liberal use of AppActivate to keep the
> focus on the right window, it's sometimes just quicker to write a
> keystroke driven process than searching for mr. unreliable's
> tutorials, as good and helpful as they are, on accessing the system
> kernel's APIs - and then finding some reference to the right one - and
> then coding it.
>
> Nuf said.
>
> Tom Lavedas
> ===========
>
http://members.cox.net/tglbatch/wsh/
> (Note: This signature was inserted using a Sendkeys routine ;o)