Connecting a script containing several IFs & several result commands

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WeThotUWasAToad
Posts: 312
Joined: 19 Nov 2013, 08:44

Connecting a script containing several IFs & several result commands

11 Feb 2019, 23:08

Hello,

In a script with multiple IF commands, how do you connect several different IF criteria with several different output commands?

For example, I've been creating a script which I want to use for transcribing audio files by use of Dragon NaturallySpeaking (DNS) voice recognition software. The process involves listening to a brief segment of audio, then pausing the audio and dictating what I just heard into the destination app (eg Notepad, Word, OneNote, etc). So two things should happen each time I press the hotkey to run the script:

• toggle Play/Pause on the audio player and
• toggle DNS On/Off

Another way to look at it is to say I want to toggle between two states:

• the media app On with DNS Off and
• the media app Off with DNS On

The tricky part is that I use several different audio sources (eg VLC, Windows Media Player [WMP], Windows Voice Recorder [WVR], YouTube, etc), but I want the script to be sort of universal (ie work for any of them). The other issue is that the different audio apps use different keyboard shortcuts to toggle Play/Pause:

Send {Space} ; for VLC, WVR,
Send ^p ; for WMP, Groove Music
Send k ; for YouTube

By the way, the keyboard shortcut I use to toggle DNS On/Off is Send {Insert}.

As for the script, I've got several lines at the beginning and a few lines at the end but I don't really know what to put in the middle:

Code: Select all

+F6::			; toggle DNS on/off & VLC, WMP, WVR, YouTube, Groove Music, or Chrome Play/Pause
SetTitleMatchMode, 2
WinGetActiveTitle, Title	; eg notepad (in order to get back each time to where I'm transcribing)
Send {Insert}						; toggle DNS on/off

IfWinExist, Windows Media Player
	{
	WinActivate, Windows Media Player
	WinWaitActive, Windows media player
	}
IfWinExist, Groove Music
	{
	WinActivate, Groove Music
	WinWaitActive, Groove Music
	}
IfWinExist, VLC
	{
	WinActivate, VLC
	WinWaitActive, VLC
	}
IfWinExist, YouTube
	{
	WinActivate, YouTube
	WinWaitActive, YouTube
	}

...

	Send {Space}						; VLC player on/off
	Send ^p							; WMP play/pause
	Send k								; YouTube play/pause
	Send {Space}					; Chrome (Amazon video) player on/off

	WinActivate, %Title%
Return
Thanks
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Connecting a script containing several IFs & several result commands

12 Feb 2019, 00:04

Else? Unless you mean you want them all on one line.

Code: Select all

if(winExist("Windows Media Player")||winExist("Groove Music")||winExist("VLC")||winExist("YouTube")){
    winActivate ; uses last found window
    winWaitActive
}
If that doesn't work (not sure if it would correctly set the last found window), could loop through an array of windows.

Code: Select all

windows:=["Windows Media Player","Groove Music","VLC","YouTube"]

for i,a in windows{
    if(winExist(a)){
        winActivate,% a
        winWaitActive,% a
        break
    }
}
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Joey5 and 259 guests