Detect game output audio volume Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CakeMan0123
Posts: 3
Joined: 25 Jul 2018, 17:17

Detect game output audio volume

25 Jul 2018, 17:27

I'm writing a simple (hopefully) script to press a few buttons when the loudness of a game reaches a threshold. (How) can I detect this? I'm not very experienced with ahk but I have looked around and cannot find a solution.

I was originally going to do this in .net, where I am more experienced, but could not find a solution, and keyboard I/O is infinity simpler in ahk.
gregster
Posts: 9087
Joined: 30 Sep 2013, 06:48

Re: Detect game output audio volume

25 Jul 2018, 17:49

You might have to regularly poll the SoundGet command (which generally seems to support the control type 'Loudness', but probably depending on your sound device). Seems like a job for SetTimer.
If your sound device isn't able to return the value, perhaps an external library or program could help (that might be automated by AHK).

Perhaps there is somethin else here: https://cse.google.com/cse?cx=010629462 ... jV3A1rBw8M
CakeMan0123
Posts: 3
Joined: 25 Jul 2018, 17:17

Re: Detect game output audio volume

25 Jul 2018, 17:58

Thanks :)

I'll check them out in the morning.
CakeMan0123
Posts: 3
Joined: 25 Jul 2018, 17:17

Re: Detect game output audio volume  Topic is solved

26 Jul 2018, 06:54

I just finished it. I used https://autohotkey.com/board/topic/18513-wait-for-sound (post #12) as a basis for it with Lexikos' Vista Audio Control Functions v2.0

Code: Select all

threshold := 0.05 ;adjust to your sound
useButton := "left" ;which mouse button uses the fishing rod? (left or right)
;GO TO LINE 42 AND CHANGE r TO YOUR DROP KEY

#Include VA.ahk
#SingleInstance, Force

active = 0

audioMeter := VA_GetAudioMeter()
VA_IAudioMeterInformation_GetMeteringChannelCount(audioMeter, channelCount)
; "The peak value for each channel is recorded over one device
;  period and made available during the subsequent device period."
VA_GetDevicePeriod("capture", devicePeriod)

!z::
	Click, %useButton%
	Sleep, 2000
	active:=Round(Abs(active-0.75),0)

	
While (active = 1)
{
	; Get the peak value across all channels.
	VA_IAudioMeterInformation_GetPeakValue(audioMeter, peakValue) 
	while (peakValue>=threshold) and (active = 1)
	{
		clickSequence()
		Sleep, 2000
		active := 1
		VA_IAudioMeterInformation_GetPeakValue(audioMeter, peakValue) 
	}
	Sleep, %devicePeriod%
}

clickSequence()
{
	Click, %useButton%
	Sleep, 300
	Send 2
	Sleep, 10
	Send ^r ;<--- replace r with drop key
	Sleep, 10
	Send 1
	Sleep, 300
	Click, %useButton%
}

!esc:: ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 219 guests