play mouse click sound while holding left button

Ask gaming related questions (AHK v1.1 and older)
Gonzalo94
Posts: 40
Joined: 17 Jul 2017, 12:56

play mouse click sound while holding left button

26 May 2018, 12:28

Is possible to simulate fasts clicks with a sound of mp3? If i do for example 100 clicks, it will be doing fasts sounds simulating the clicks, any idea is welcome
(i already have a rapidfire left click that will click fast when is holding the left button) and i have a mp3 short sound

there is the code

Code: Select all

SetBatchLines -1
ListLines, Off
$LButton::
MouseGetPos, x, y ; retrieves the current position of the mouse cursor
if (Between(532, 771, x) and Between(203, 523, y)) {
	While (GetKeyState("LButton", "P")) {
		click
    Sleep, -1
	}
return
}
send, {LButton}
return ; end of the hotkey subroutine
#If


Between(__lowerBound, __upperBound, __var) {
If __var between %__lowerBound% and %__upperBound%
	return true
return false
}
Rangerbot
Posts: 31
Joined: 02 Mar 2018, 10:33

Re: play mouse click sound while holding left button

26 May 2018, 16:26

Code: Select all

SetBatchLines -1
ListLines, Off

Pause::Reload

$LButton::
	MouseGetPos, x, y ; retrieves the current position of the mouse cursor
	;if (Between(532, 771, x) and Between(203, 523, y)) {
		While (GetKeyState("LButton", "P")) {
			click
			;SoundPlay, *-1		;plays a console beep, exchange this with your mp3 file's path
			SoundBeep,,5		;plays a console beep for 5ms
			Sleep, -1
		}
	return
	;}
	send, {LButton}
return ; end of the hotkey subroutine

Between(__lowerBound, __upperBound, __var) {
	If __var between %__lowerBound% and %__upperBound%
		return true
	return false
}
is this what you were looking for? I don't think you would be able to hear the sound if it's called every click.
Gonzalo94
Posts: 40
Joined: 17 Jul 2017, 12:56

Re: play mouse click sound while holding left button

27 May 2018, 00:03

Rangerbot wrote:

Code: Select all

SetBatchLines -1
ListLines, Off

Pause::Reload

$LButton::
	MouseGetPos, x, y ; retrieves the current position of the mouse cursor
	;if (Between(532, 771, x) and Between(203, 523, y)) {
		While (GetKeyState("LButton", "P")) {
			click
			;SoundPlay, *-1		;plays a console beep, exchange this with your mp3 file's path
			SoundBeep,,5		;plays a console beep for 5ms
			Sleep, -1
		}
	return
	;}
	send, {LButton}
return ; end of the hotkey subroutine

Between(__lowerBound, __upperBound, __var) {
	If __var between %__lowerBound% and %__upperBound%
		return true
	return false
}
is this what you were looking for? I don't think you would be able to hear the sound if it's called every click.
idk why not working for me with the sound .wav
can you explain to me how to change it? the .wave sound is in here

Code: Select all

C:\Users\gonzalo\Documents\Nueva carpeta
Rangerbot
Posts: 31
Joined: 02 Mar 2018, 10:33

Re: play mouse click sound while holding left button

27 May 2018, 09:43

you wont be able to hear the sound because it is played many hundreds of times a second.
i used SoundBeep and commented out SoundPlay because it would just fill your audioCard and create a mess sound wise.
I have visual alerts turned on for hearing impairment in the Accessibility page of Control Panel.
When I run the above script it makes a light show out of my monitor despite no sound coming through.
If you would like to play your .wav, move it into the same directory as your .ahk file and change the following lines

Code: Select all

click
			;SoundPlay, *-1		;plays a console beep, exchange this with your mp3 file's path
			SoundBeep,,5		;plays a console beep for 5ms
			Sleep, -1
into

Code: Select all

click
			SoundPlay, %A_ScriptDir%\YOURSOUNDFILE.wav		;this will load the directory of your .ahk file and look for "YOURSOUNDFILE.wav" in the same folder.
			;SoundBeep,,5		;plays a console beep for 5ms
			Sleep, -1
if your sound is still not playing, amend the WAIT command to SoundPlay. This will force it to wait until the sound is done being played before clicking again.

Code: Select all

SoundPlay, %A_ScriptDir%\YOURSOUNDFILE.wav, WAIT
I might imagine that putting "#MaxThreads 2" (or more) at the very beginning of your script might allow it to play the sound along the running code.
This is just a guess because I have no idea what type of thread SoundPlay produces or if it will make a thread for itself.
Disbade
Posts: 1
Joined: 15 Feb 2021, 09:55

Re: play mouse click sound while holding left button

15 Feb 2021, 10:00

Is there a way to make it so that it only plays when the LButton is held down and not just a a click? Because currently for me the sound plays when there is only a click (it works when held down but I only want it to be played when held down and not a single click)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 46 guests