AutoHotkey Community

It is currently May 27th, 2012, 10:31 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 85 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject:
PostPosted: September 3rd, 2011, 11:58 am 
Offline

Joined: May 11th, 2011, 11:51 pm
Posts: 31
tjmonk15 & Guest1 - just tried it, seems to be working excellently! Thanks! :D

EDIT: Well, it gives a little trouble to start working, but it works.

(I get the "Cannot find either device" message a couple times first)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2011, 12:38 pm 
Do I need a program to execute your code, or can I copy your code and paste it in a file? Which file type should it be?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2011, 1:29 pm 
I don't run external .exe files, for security reasons, so I've created a vbs file with a few .bat files to switch between my 3 output profiles (default sound card, usb card and bluetooth). I posted all the code at http://www.4shared.com/file/RPRH0gfP/sound_scripts.html

Great. It works for me now. Any way to suppress the dialog: "New Sound Card: XXX XXXX XXX"??


Report this post
Top
  
Reply with quote  
PostPosted: December 1st, 2011, 6:17 pm 
Hi guys, So I created a script that switches the default sound card on open and runs a program on ASIO4all. When it closes it shuts down again. I want to a add a part that basically allows me to use the [ en ] keys to control the volume of the secondary soundcard (which is in use by ASIO4all) and that I CAN change the volume of.

Can anybody help me?


Report this post
Top
  
Reply with quote  
 Post subject: Three devices
PostPosted: December 4th, 2011, 1:44 am 
Offline

Joined: January 8th, 2010, 2:19 am
Posts: 5
I have three endpoints I regularly switch between. Sometimes the USB device isn't plugged in, so all the techniques that depend on the device being in a particular position in the list ended up being unreliable when devices present changed.

Here's another take at it keying off a part of the endpoint identifier and based on all the great work in this post, plus a moving the window off-screen and a traytip showing activated device

Code:
ActivateSoundDeviceEndpoint(DeviceName) {
   ; close sound panel if it's open
   IfWinExist Sound ahk_class #32770
      WinClose

   ; open sound panel
   Run rundll32.exe shell32.dll`,Control_RunDLL mmsys.cpl`,`,0  ; similar to Run mmsys.cpl
   WinWait Sound ahk_class #32770

   ; arrow-key movement fails if pointer is over window; get window out of the way
   WinMove, 0,8000

   ; get, then iterate over list of sound device endpoints
   ControlGet, len, List, Count, SysListView321
   Loop %len%
   {
      ; select first or next endpoint
      ControlSend, SysListView321, {Down}

      ; get endpoint info
      ControlGet, Device_Info, List, Selected, SysListView321

      ; endpoint contans our DeviceName?
      IfInString, Device_Info, %DeviceName%
      {
         ; extract endpoint title and device it's on into MatchedTitle and MatchedDevice
         RegExMatch(Device_Info, "(?P<Title>.+)\t(?P<Device>.+)\t", Matched)

         ; set this endpoint as system default (activate it)
         ControlClick, &Set Default
         ControlClick, OK
         WinWaitClose

         ; play a sound on the newly activated device
         SoundPlay, *64  ; Asterisk (info)

         ; show a tray tip with the new endpoint
         TrayTip %MatchedTitle%, %MatchedDevice% is now active, 2, 17 ; 2 seconds, info icon (1) without sound (+16)
         SetTimer, RemoveTrayTip, 2000  ; TrayTip durations under 10 seconds don't work, remove ourselves after 2 second timer

         ; stop iterating
         Break
      }
   }
   return
}


RemoveTrayTip() {
   SetTimer, RemoveTrayTip, Off
   TrayTip  ; without parameters, removes displayed traytip
}


In my case, I wanted to bind to a single key, varying which sound endpoint activates by the number of times I press that key in succession. ins0mniaque's PatternHotKey provided the mechanism

Code:
; Activate sound device endpoint
;     '.'   (sinle short press)  activates Bluetooth headset
;     '..'  (double short press) activates Speakers
;     '...' (triple short press) activates USB headset
ScrollLock::PatternHotKey(".->ActivateSoundDeviceEndpoint(Bluetooth)"
                        , "..->ActivateSoundDeviceEndpoint(Klipsh)"
                        , "...->ActivateSoundDeviceEndpoint(Logitech)")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2011, 7:36 pm 
Can i assign this script to MUTE button on keyboard?
If so how would one do that.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2011, 12:56 am 
Offline

Joined: January 8th, 2010, 2:19 am
Posts: 5
To assign something to the mute key, look at the List of Keys, Mouse Buttons, and Joystick Controls to see that Autohotkey knows the Mute key as Volume_Mute.

Try replacing the part to the left of the :: with Volume_Mute, as in
Code:
Volume_Mute::PatternHotKey()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 16th, 2011, 11:10 pm 
Weird... cant get it to work from mute key


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 1st, 2012, 6:48 am 
Offline

Joined: January 1st, 2012, 6:45 am
Posts: 1
i'm not sure how to look for this, but is there any way to force the completion of the script made by tjmonk15 even if the mouse is on the 'Sound' window? Either that or minimize it so it's not seen?

Thanks and thank you for the code. You guys have helped me so much






Edit: Scratch that. i just changed the ControlClick,OK to Send {enter} and it works. The window pops up, does what i need, and closes, no matter if the mouse is on the window.

P.S. Figures that i will figure it out after i have posted. Just thought that i would post this for others who are looking to refine it so it doesn't stay open.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2012, 9:50 pm 
If you are running a Dutch version of Windows7 you could use the following script.

#g::
Run, mmsys.cpl
WinWait,Geluid
ControlSend,SysListView321,{Down}
ControlGet, isEnabled, Enabled,,&Als standaard instellen
if(!isEnabled)
{
ControlSend,SysListView321,{Down 2}
}
ControlClick,&Als standaard instellen
ControlClick,OK
WinWaitClose
return


Report this post
Top
  
Reply with quote  
 Post subject: The one for my use.
PostPosted: January 13th, 2012, 8:35 am 
Offline

Joined: October 31st, 2005, 9:11 pm
Posts: 8
I've taken what I found here for my use. This will cycle through all available devices starting from the last device.

aka: If the current default device is #2, it will start from #3 and work its way down till it finds a device it can enable. When it reaches bottom it will cycle back to the top. It stores the last device in a ini file.

There is much improvement and cleaning up that can be done to it. For now it just works :3.

Code:
#+a::
IfWinExist Sound
{
   WinKill Sound
}
Run, mmsys.cpl
WinWait,Sound
MouseGetPos,xpos,ypos
if (xpos<600) {
   WinMove,800,0
} else {
   WinMove,10,10
}
devicecnt = 0
IfExist, ahk.ini
{
IniRead, lastdevice, ahk.ini, Audio, LD
} else {
IniWrite, 1, ahk.ini, Audio, LD
lastdevice := 1
}

deviceloop := lastdevice
ControlGet, len, List, Count, SysListView321
Loop %len%
{
if lastdevice = %len%
{
    ControlSend,SysListView321,{Home}
    lastdevice :=
    deviceloop :=
    ++devicecnt
}
else
{
if deviceloop > 0
{
Loop %deviceloop%
{
ControlSend,SysListView321,{Down}
--deviceloop
++devicecnt
}
deviceloop := 0
} else {

if devicecnt = %len%
{
    ControlSend,SysListView321,{Home}
   devicecnt := 1
}
else {
++devicecnt
    ControlSend,SysListView321,{Down}
}
}
}
    ControlGet, isEnabled, Enabled,,&Set Default
    if(isEnabled)
    {
        ControlClick,&Set Default
        Sleep 500
        ControlClick,OK
      IniWrite, %devicecnt%, ahk.ini, Audio, LD
   devicecnt :=
        Return
    }
}
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject: F11 = 2 & F12 = 1
PostPosted: January 30th, 2012, 11:39 pm 
Mon script en modifiant les votres ^^

^!F11::
Run, mmsys.cpl
WinWait,Son
ControlSend,SysListView321,{Up 5}
if(!isEnabled)
{
ControlSend,SysListView321,{Down 1}
}
Send !{D}
ControlClick,OK
return

^!F12::
Run, mmsys.cpl
WinWait,Son
ControlSend,SysListView321,{Up 5}
Send !{D}
ControlClick,OK
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 12th, 2012, 2:38 am 
I haven't found an AHK solution for changing audio device in Win 7 without sending commands to a GUI.

I did however find this non-AHK code that seems to solve that: http://www.daveamenta.com/2011-05/progr ... windows-7/

But I'm not good enough at coding to be able to translate that into AHK code. Hopefully someone else here is.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2012, 8:42 pm 
Offline

Joined: February 15th, 2012, 8:30 pm
Posts: 2
Ok, I've got something working very well thanks to borna's link. I've modified the code to switch the playback device for all roles (console, multimedia, communication). The original code would only switch the default sound device for console (and the previous default would be assigned multimedia and communication roles). I've also modified it so that the return value is the number of available devices when called with no arguments.

Here is the zip file with source code and binary. The exe is in the "Release" directory. If you don't trust me (and why would you), you can download the zip file, download and install Visual C++ Express (for free), and open the .sln file. Hit F7 and it will build a fresh release.

Move the EndPointController.exe file somewhere on your %PATH% (I put mine in C:\Windows\System32\). Run it from cmd to get a list of your devices with associated device IDs. And here's the AHK code:

Code:
; Cycle through playback devices
^!s::
if not TotalEndPoints {
   TotalEndPoints = 0
   RunWait, %comspec% /c EndPointController > %A_Temp%\endpoints.txt,, Hide
   Loop, Read, %A_Temp%\endpoints.txt
      TotalEndPoints++
   FileDelete, %A_Temp%\endpoints.txt
}
CurrentEndPoint++
CurrentEndPoint := Mod(CurrentEndPoint, TotalEndPoints)
RunWait, %comspec% /c EndPointController %CurrentEndPoint% ,, Hide
return

; Switch to playback device 0
^!0::
RunWait, %comspec% /c EndPointController 0 ,, Hide
return

; Switch to playback device 1
^!1::
RunWait, %comspec% /c EndPointController 1 ,, Hide
return

; Switch to playback device 2
^!2::
RunWait, %comspec% /c EndPointController 2 ,, Hide
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2012, 11:07 pm 
Offline
User avatar

Joined: November 19th, 2010, 9:54 am
Posts: 184
Very nice tomchuk :)
But cycling/^!s:: does nothing on my side.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 85 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, chaosad, robotkoer, Yahoo [Bot] and 73 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group