There are a couple questions in the comments I've put in it
Code: Select all
#SingleInstance
;#NoTrayIcon
FileInstall, micOff.ico, micOff.ico
FileInstall, micOn.ico, micOn.ico
FileInstall, toggle.ini, toggle.ini
;FileInstall, toggle.ahk, toggle.ahk ;is there a way to include the ahk you are attempting to compile in the compile to be extracted upon running the exe
PgUp::
isExist:=WinExist("ahk_exe rundll32.exe ahk_class #32770")
Run, % "rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,recording",,, uPID
WinWait, % "ahk_pid"uPID,, 1
WinWait,Sound
Send {CTRL DOWN}{Down}{CTRL UP}
ControlGet, List, List,, SysListView321, % "ahk_pid"uPID
FileRead, OutputVar, toggle.ini
Loop, Parse, List, `n
{
IfInString, A_LoopField, %OutputVar%
{
ControlClick,&Properties
Send {CTRL DOWN}{Tab}{CTRL UP}
Send {Space}
Send {Enter}
break
}
else
{
ControlSend,SysListView321,{Down}
}
}
WinWait,Sound
Send {Esc}
Menu,Tray,Icon,micOn.ico,,1
Return
PgDn::
isExist:=WinExist("ahk_exe rundll32.exe ahk_class #32770")
Run, % "rundll32.exe shell32.dll,Control_RunDLL mmsys.cpl,,recording",,, uPID
WinWait, % "ahk_pid"uPID,, 1
WinWait,Sound
Send {CTRL DOWN}{Down}{CTRL UP}
ControlGet, List, List,, SysListView321, % "ahk_pid"uPID
FileRead, OutputVar, toggle.ini
Loop, Parse, List, `n
{
IfInString, A_LoopField, %OutputVar%
{
ControlClick,&Properties
Send {CTRL DOWN}{Tab}{CTRL UP}
Send {Space}
Send {Enter}
break
}
else
{
ControlSend,SysListView321,{Down}
}
}
WinWait,Sound
Send {Esc}
Menu,Tray,Icon,micOff.ico,,1
Return
Home::
Reload
Del::
Menu,Tray,Icon,micOff.ico,,1 ; Need to know how to set the Icon to AHK's Suspend icon as my custom ones above override once used
Suspend
Return
Ins::
Menu,Tray,Icon,micOff.ico,,1 ; Need to know how to set the Icon to AHK's Pause icon as my custom ones above override once used
Pause
Return
End::
ExitApp
But I'd like the icon to switch between micOff.ico and micOn.ico, respective to the actual state of the "listen" option.
I know I need to put:
[code]Menu,Tray,Icon,micOff.ico,,1[/code]
and
[code]Menu,Tray,Icon,micOn.ico,,1[/code]
somewhere but not sure where.
I'll probably compile it so the default Icon is one of the two and then just need...
OH I think I got it. Will edit my own post if I do. (Or remove it if needed)
I think the code will have to be re-written a bit more than I can fathom at the moment. I am not happy with the way I've made it work. As it stands the PgUp turns on the mic and PgDn turns it off but only in icon as both will actually toggle it SOO close! maybe?
Anyway, anyone wanna contribute?
Final Edit:
After some help from AHK DIscord I found a 3rd party software that was able to change the listen state via command so here's the final script. You can review it to figure out the program name and then find the program online.
Code: Select all
;Version: toggle.microphone.0.06
#SingleInstance, Force
FileInstall, micOff.ico, micOff.ico
FileInstall, micOn.ico, micOn.ico
FileInstall, toggle.ini, toggle.ini ; enter the name of the device you want to toggle in this file
FileInstall, soundvolumeview-x64.zip, soundvolumeview-x64.zip
FileInstall, SoundVolumeView.exe, SoundVolumeView.exe
FileInstall, toggle microphone.0.06, toggle microphone.0.06.ahk ;note in order to include the .ahk in the compiled version you need to copy the file and remove it's extention ... this line will then add it to the exe.
PgUp::
FileRead, OutputVar, toggle.ini
Run, SoundVolumeView.exe /SetListenToThisDevice "%OutputVar%" 1
Menu,Tray,Icon,micOn.ico,,1
Return
PgDn::
FileRead, OutputVar, toggle.ini
Run, SoundVolumeView.exe /SetListenToThisDevice "%OutputVar%" 0
Menu,Tray,Icon,micOff.ico,,1
Return
Home::
Reload
Del::
;Menu, tray, icon, AutoHotkey.exe, 3 ;If you attempt to use this it fails to respond to the Del key again
Suspend
Return
Ins::
Edit
Return
End::
ExitApp