"page up" to launch & control volume

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
haxxx
Newbie
Posts: 5
Joined: Tue Feb 23, 2010 2:53 pm

"page up" to launch & control volume

Post by haxxx » Tue Feb 23, 2010 9:51 pm

I've been trying to learn macro scheduler by myself with varying degrees of success. I've created a shortcut to my volume control on my c drive and use my page up key and page down keys for a shortcut. But what i really want to do is to click page up (or down) which executes sndvol32 sends Tab (to activate slider) then "Press down"
without me releasing page up (or down) key and without generating child windows. volume window would then close on release of up or down key.
Any help would be greatly appreciated.

haxxx.

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Feb 23, 2010 11:07 pm

Something like this? This has to run full time. Would probably be best compiled but it will work as a script. While it is running, press and hold the Page Up or Page Down keys. The volume will go up or down. Release the key and the Volume Control window will close. If you want control of the volume. Hold either Page Up or Page Down, then press the other key and the volume can be changed one notch at a time.

Press Shift+Esc to close this

Code: Select all

//VK33 = Page up
OnEvent>Key_Down,VK33,0,Volume
//VK34 = Page down
OnEvent>Key_Down,VK34,0,Volume

SRT>Volume
    //Only run this code if the flag variable value is 0
    If>KeyReleaseFlag=0
      //Check to see if volume control is open before running the program to open it again.
      IfWindowOpen>Volume Control
      Else
        Let>Rp_wait=0
        Run>sndvol32
        WaitWindowOpen>Volume Control
      EndIf
      Wait>0.2
      SetFocus>Volume Control
      Press Tab
    EndIf

  //Run this line setting the flag variable value to 1 every time the subroutine is
  //called... which will be continuosly as long as the pressed key is held down.
  Let>KeyReleaseFlag=1
END>Volume

//You need a flag variable for detecting and controlling the release of a key
Let>KeyReleaseFlag=0

//This loop runs waiting for a usable keypress
Label>Loop
  Wait>0.01
  //This "If" block in conjunction with the Key_Down OnEvent allows the script to know if
  //the keys are pressed and released.  While the key is pressed the OnEvent keeps firing.
  //In the Subroutine called by the Key_Press OnEvent> the flag variable value is set to 1.
  //The Loop keeps trying to raise the value of the flag variable up to 10 but as long as the 
  //key is pressed the Key_Down subroutine keeps resetting the value to 1.  When the key is
  //finally released,  the loop will raise the flag variable value to 10 and then we can
  //set the flag variable value back to 0 and perform other tasks associated with the key
  //release,  such as closing the Volume Control window.
  If>KeyReleaseFlag>0
    Add>KeyReleaseFlag,1
    If>KeyReleaseFlag>10
      Let>KeyReleaseFlag=0
      CloseWindow>Volume Control
    EndIf
  EndIf
Goto>Loop

haxxx
Newbie
Posts: 5
Joined: Tue Feb 23, 2010 2:53 pm

warning message

Post by haxxx » Tue Feb 23, 2010 11:26 pm

I tried your script and received the error message:
Line 17 specified window volume control not present,
any subsequent keysends in script may cause exceptions.
"abort" "ignore".

??

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Feb 23, 2010 11:29 pm

Hmmmmm. Perhaps the Volume Control window is not named Volume Control on all Microsoft OSs. I'm running XP and this script works for me.

Do you see the Volume Control window open at all?

haxxx
Newbie
Posts: 5
Joined: Tue Feb 23, 2010 2:53 pm

Works

Post by haxxx » Wed Feb 24, 2010 1:18 pm

I apologize error was on my end.
Two Questions though, 1. Where could i put a "wait" so the window doesn't close so quickly after i release the key, in case i want to micro adjust volume. 2. I've seen somewhere a "delay" variable, could that be used to slow the actual speed of the volume change? as it is If u have heavy fingers the slider moves rapidly. 3. If i set it to run at startup, is it okay to have it waiting for the entire time the PC is on, not a problem to me (just curious).

Thanks.

haxxx
Newbie
Posts: 5
Joined: Tue Feb 23, 2010 2:53 pm

Post by haxxx » Wed Feb 24, 2010 1:33 pm

Let>KeyReleaseFlag=0
Wait>3.01
CloseWindow>Master Volume
EndIf

Ok i put a 3 second wait here and that works fine. Now i have to figure out a micromovement for the slider.

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Feb 24, 2010 2:17 pm

I see you've answered your own question 1. Excellent!

For question 2. I don't know of any "delay" variables except for "SK_DELAY" which can be used to slow text input when using the SendText> function. However, as I said earlier.
If you want control of the volume. Hold either Page Up or Page Down, then press the other key and the volume can be changed one notch at a time.
Question 3. It is most likely alright to have this running 100% of the time. As long as there is a short Wait> in the "Loop". However, I could see a problem where it might interfere with using the Page up or Page down keys in other applications. A slight modification to the OnEvent> line could allow you to use a modifier key and perhaps avoid conflict. See help for OnEvent> for more detail.

haxxx
Newbie
Posts: 5
Joined: Tue Feb 23, 2010 2:53 pm

Post by haxxx » Wed Feb 24, 2010 3:13 pm

Thanks man, ure the boss, I'll see if i can figure it out.
Haxxx.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts