script that will toggle system sound on and off also other code

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Obama_The_Llama
Posts: 10
Joined: 27 Jul 2017, 09:39
Location: USA

script that will toggle system sound on and off also other code

27 Jul 2017, 09:58

I want my system sound to toggle on and off by pressing Ctrl + Delete. I already have some of it here;
#installkeybdhook
#usehook
^Delete::
SoundSet, 0
But I don't have the part that lets me press it again which I would assume is some kind of loop but I'm a noob so I don't know how to do that. Also I would like my skype window to Minimize when I press CTRL + Delete and unminimize when I press it again. Most of the time This isn't always going to be an active window but I also want it to do the same thing when it is. And I would like this to mute my microphone at the same time.
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: script that will toggle system sound on and off also other code

27 Jul 2017, 13:24

Hi.
Using the search function will offer tons of examples for toggle a key.
Look here for example. I've found it by searching for "toggle key".

I'm using an example from the help file to increase or decrease the sound of my system. Look here.

For minimizing a window there is a command called WinMinimize.
Einfach nur ein toller Typ. :mrgreen:
Obama_The_Llama
Posts: 10
Joined: 27 Jul 2017, 09:39
Location: USA

Re: script that will toggle system sound on and off also other code

27 Jul 2017, 17:36

I have come a long way with my code but I have a problem; when I try to replace the window title from notepad to anything else it doesn't work. the window that I want to minimize is the skype window (not the live conversation window that it makes when you go in full screen) also I've tried a script that tests the windows Active ID to no luck.
^Delete::
{
Toggle := !Toggle
if Toggle
#installkeybdhook
#usehook
SoundSet, 0

else
#installkeybdhook
#usehook
SoundSet, 100
}
{
IfWinExist,ahk_class Notepad
WinGet,WinState,MinMax,ahk_class Notepad
If WinState = 0
WinMinimize
else
WinRestore,ahk_class Notepad
}
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: script that will toggle system sound on and off also other code

27 Jul 2017, 18:08

[EDIT: ATTENTION - Code below is incorrect!]

Hi.
I can give you only a bit syntax support.
Change to

Code: Select all

^Delete::
Toggle := !Toggle
#installkeybdhook
#usehook
if (Toggle = Toggle)
SoundSet, 0
else
SoundSet, 100
...
I don't know what or how the rest of your code is doing or is processed. Hope someone else can give better support. Maybe it is a SetTitleMatchMode problem.

EDIT: Now I know.
"WinGet,WinState,MinMax,ahk_class Notepad"
ahk_class Notepad is not the title. It is something called ahk_class.
You can find the class of your desired window by using Window Spy. Look to this tread. It is in german language. Maybe you understand. Look for the pictures and find your ahk_class.

Right click on the symbol of a running ahk script at the right side of your windows taskbar. Choose Window Spy and then position your mouse over the window, you want to analyse.
Last edited by divanebaba on 27 Jul 2017, 18:48, edited 1 time in total.
Einfach nur ein toller Typ. :mrgreen:
Obama_The_Llama
Posts: 10
Joined: 27 Jul 2017, 09:39
Location: USA

Re: script that will toggle system sound on and off also other code

27 Jul 2017, 18:30

That only made the toggle not work but thanks for showing me the space between the else.
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: script that will toggle system sound on and off also other code

27 Jul 2017, 18:37

[EDIT: ATTENTION - first code is untested and probably INCORRECT - Use second code :silent:]
Oh.
Your right. It has to be something like this:

Code: Select all

^Delete::
if (Toggle = Toggle)
Toggle := !Toggle
#installkeybdhook
#usehook
if (Toggle = Toggle)
SoundSet, 0
else
SoundSet, 100
...
Code below is a bit different, but it is a way, I would do. #installkeybdhook and #usehook I never used, so I dont know, if it could be taken out of the hotkey

Code: Select all

#installkeybdhook
#usehook
toggle = yes

^Delete::
if (Toggle = yes)
{
SoundSet, 0
Toggle = no
}
else
{
SoundSet, 100
Toggle = yes
}
...
Einfach nur ein toller Typ. :mrgreen:
Obama_The_Llama
Posts: 10
Joined: 27 Jul 2017, 09:39
Location: USA

Re: script that will toggle system sound on and off also other code

28 Jul 2017, 14:05

I have fixed the issue of it not working with anything except notepad by changing ahk_class to ahk_exe and I had it opening Skype and closing it fine yesterday but when I went to try it again today the it minimized and unminimized at the same time. The last lines is me trying to minimized skype in fullscreen (I had this code yesterday aswell) and I tested to see if that was the issue and it was to a certain extent it fixed the issue of it minimizing and unminimizing at the same time but now the WinRestore line doesn't work and that's where it is now. Before I turned my computer off I tested to see if it worked and it did no one changed it overnight to my knowledge.
^Delete::
#installkeybdhook
#usehook

{
Toggle := !Toggle
if Toggle
SoundSet, 0
else
SoundSet, 100
}
{
IfWinExist,ahk_exe Skype.exe
WinGet,WinState,MinMax,ahk_exe Skype.exe
If WinState = 0
WinMinimize
else
WinRestore,ahk_exe Skype.exe
}

;IfWinExist,ahk_class tSkMainForm
;WinGet,WinState,MinMax,ahk_class tSkMainForm
;If WinState = 1
; WinMinimize
;else
;sleep 1000
;WinRestore,ahk_class tSkMainForm
Obama_The_Llama
Posts: 10
Joined: 27 Jul 2017, 09:39
Location: USA

Re: script that will toggle system sound on and off also other code

28 Jul 2017, 14:55

ok never mind I figured it out I needed to put a timer before the restore line
Obama_The_Llama
Posts: 10
Joined: 27 Jul 2017, 09:39
Location: USA

Re: script that will toggle system sound on and off also other code

28 Jul 2017, 15:13

I'm working on the code that minimizes the conversation window and when I press the control and delete it minimize the window but it doesn't minimize the second window like it would normally when that's the only window there. I feel like I need to implement some kind of code that communicates with each other to allow this to happen where would I start?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 315 guests