r/AutoHotkey•
yfph

Is it possible to send a keystroke sequence to a background program (here, MP3Tag) where the keystrokes do not interfere with the active window?

AHK v1.0.48.05

The key sequence below works fine when mp3tag is the active window and I don't steer away from it. It breaks down when I select another active window obviously.

Now, how do I make it where the key sequence is sent to a background instance of mp3tag (Mp3tag.exe) and only mp3tag receives and processes the key seqeuence? I'd like to make it so that executing the sequence doesn't interfere with whatever I'm doing in the active window of another program. Thanks!

#s::
InputBox, times, Number of tracks (more than on album)
	if (times > 0) ; test if it is a number
	{
		Loop % times
		{
			Send !s ; alt+s to bring up tag sources menu
			Send a
			Send s
			Send {Enter}
			Send {Enter}
			Sleep 1000
			Send {Down}
		}	return
	}

Posted Jun 14, 2017, 12:48 AM UTC · edited

25
GroggyOtter•

ControlSend is what you're looking for.

It's used to send text directly to something, even if it's not active.

Edit:

#s::
	SetKeyDelay, 25
	InputBox, times, Number of tracks (more than on album)
		if (times > 0) ; test if it is a number
		{
			Loop % times
			{
				; If you know the control name (use windowspy) put it in
				; the blank area right after controlsend.
				ControlSend, , !sas{Enter 2}, ahk_exe mp3tag.exe
				Sleep 1000
				ControlSend, , {Down}, ahk_exe mp3tag.exe
			}
		}
return
2
yfphOP•

Thanks for the reply. I tried the following but after the entering the number of loops in the inputbox, there was nothing.

#s::
	SetKeyDelay, 25
	InputBox, times, Number of tracks (more than on album)
		if (times > 0) ; test if it is a number
		{
			Loop % times
			{
				; If you know the control name (use windowspy) put it in
				; the blank area right after controlsend.
				ControlSend, ahk_class Afx:00400000:b:00010003:00000006:22E51B61, !sas{Enter 2}, ahk_exe mp3tag.exe
				Sleep 1000
				ControlSend, ahk_class Afx:00400000:b:00010003:00000006:22E51B61, {Down}, ahk_exe mp3tag.exe
			}
		}
return

I also tried Afx:00400000:b:00010003:00000006:22E51B61 and Mp3tag v2.81 as control names to no avail.

EDIT: Found ClassNN is SysListView321

The following doesn't work either:

#s::
	SetKeyDelay, 25
	InputBox, times, Number of tracks (more than on album) test3
		if (times > 0) ; test if it is a number
		{
			Loop % times
			{
				; If you know the control name (use windowspy) put it in
				; the blank area right after controlsend.
				ControlSend, SysListView321, {Alt down}s{Alt up}as{Enter 2}, ahk_exe Mp3tag.exe
				Sleep 1000
				ControlSend, SysListView321, {Down}, ahk_exe Mp3tag.exe
			}
		}
return
1
GroggyOtter•

So I use MP3Tag myself. Great program.
Alt+S is the Tag Sources menu. But neither A nor S are shortcuts for anything in that menu.

Which menu item are you trying to select? And what's your end goal?

1
yfphOP•

I wrote a web source script that scrapes a music db that has per track data and I keyed the script to a key sequence (A and S following the selection of the tag sources menu, say "Last.fm > #1 SongID" where the filename.src is L&ast.fm#&1 &SongID.src. & is the hotkey and #& denotes a submenu. Alt+a, a, s would then select the aforementioned web source script, obtain per track metadata and then move on to the next track.

Having obtained SongIDs for each track on an album, I have mp3tag execute the web source script for each track to save me from carpal tunnel syndrome. I guess for one album is fine, but imagine if I was trying to do it manually for a large box set. Automation is the way to go and it works so long as mp3tag is the active window.

My endgame is to do this in the background: send the key sequence to mp3tag, loop it x times depending on how many tracks I find on the album, and ensure that only mp3tag receives and acts upon the key sequence while I'm working on something else in another window.

I don't know if this is possible with AHK. AHK's documentation isn't the clearest or most user friendly documentation I've come across.

1
CoCaptainJack•

In my experience, ControlSend doesn't always not interfere with the active window. also, sometimes ControlSend needs to be sent to the foreground or else it completely misses the inputs.

Advice?

0