playsound and overlay text

Get help with using AutoHotkey and its commands and hotkeys
kentpachi
Posts: 62
Joined: 15 May 2016, 01:23

playsound and overlay text

27 Jan 2018, 13:21

I have a very simple script that first it find the image and when its found it will play a sound
this is the script

Code: Select all

loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 0, 0, 552, 70, 1.png
If ErrorLevel = 0
SoundPlay, 1.wav


}

problem is. it only play the sound after the image is gone. how do i fix this?

----------------------------------------
OVERLAY TEXT
How do i display a overlay text on the game i play?
example. this code

Code: Select all

loop
{
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 0, 0, 552, 70, 1.png
If ErrorLevel = 0

}
after the image is found . display a overlay text or overlay image that doesnt hinder on game. textsplash hinder on clicks and not overlay display at all
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: playsound and overlay text

27 Jan 2018, 18:04

How long is the image around for? Does your 1.wav file have some silence or very low volume in the beginning? Try using a MsgBox instead of SoundPlay for testing. MsgBox should be reliably instantaneous.

(As an aside, you don't need the CoordMode inside of the Loop command; once it's set for that thread (hotkey) or in the auto-execute section, it'll persist.)

I would make a GUI. You can use the parameter "NA" or "NoActivate" to not activate the GUI when you use Gui, Show command. You can use the +AlwaysOnTop amongst the Gui options to make it sit on top of your game. You may need this option as well to make it click-through +E0x20.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: playsound and overlay text

27 Jan 2018, 18:46

You can use SplashImage to display overlay text. For example:

Code: Select all

SplashImage, , B W200, The image was found!
Sleep, 2000
SplashImage, Off
If you want to play the sound slightly after the text is displayed, rather than slightly before, you can move your SoundPlay line to after the first SplashImage line.
kentpachi
Posts: 62
Joined: 15 May 2016, 01:23

Re: playsound and overlay text

27 Jan 2018, 22:23

Osprey wrote:You can use SplashImage to display overlay text. For example:

Code: Select all

SplashImage, , B W200, The image was found!
Sleep, 2000
SplashImage, Off
If you want to play the sound slightly after the text is displayed, rather than slightly before, you can move your SoundPlay line to after the first SplashImage line.
it still doesnt click through. not overlay. it still hinders my game clicks


thank you for your time bro
Last edited by kentpachi on 27 Jan 2018, 22:28, edited 1 time in total.
kentpachi
Posts: 62
Joined: 15 May 2016, 01:23

Re: playsound and overlay text

27 Jan 2018, 22:28

Exaskryz wrote:How long is the image around for? Does your 1.wav file have some silence or very low volume in the beginning? Try using a MsgBox instead of SoundPlay for testing. MsgBox should be reliably instantaneous.

(As an aside, you don't need the CoordMode inside of the Loop command; once it's set for that thread (hotkey) or in the auto-execute section, it'll persist.)

I would make a GUI. You can use the parameter "NA" or "NoActivate" to not activate the GUI when you use Gui, Show command. You can use the +AlwaysOnTop amongst the Gui options to make it sit on top of your game. You may need this option as well to make it click-through +E0x20.
*1.wave is 15sec. no silence in the beginning
*tried msgbox but still hinder while in-game and my clicks doesnt work inside msgbox
* remove the coordmode. thank you bro
*i have never tried GUI. can you make it please? the "click-through +E0x20" i think its the solution. sounds like thats what i need, be able to click through ahk overlays while in my game cuz msgbox.splashtext doesnt click through

Thank you for your time bro
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: playsound and overlay text

27 Jan 2018, 23:19

Are any actions occuring outside the loop after the soundplay? If you just want to soundplay, then it's fine as is. But if you have other code that you are executing when the image is found, make sure your SoundPlay is set to asynchronous. (Add ,1 after the sound file I believe.)

The point of MsgBox was just to test that AHK is responding speedily to finding the image.

Quick GUI; I suggest you play around with GUI in a separate script to get what you want.

Code: Select all

Gui, Add, Text,,Overlay
Gui, +AlwaysOnTop +E0x20 +LastFound
WinSet, Transparent, 255
Gui, Show, NA, OverlayTitle
return
I learned something new whipping this up for you. I've suggested using +E0x20 for years, but didn't realize (or since forgotten) that you need to make the window transparent for it to work. I did find that a minimum transparency of 255 (the highest numerical value; if it was set to 0, the window would be invisible, so a 255 makes it opaque) is necessary to make it work as a click-through. But you may still want to have it partially transparent, otherwise you wouldn't necessarily know what you're clicking on.

Close the overlay by right clicking on the window icon in the taskbar and selecting close. Otherwise, exit your script, or reload it if you tie the overlay to a hotkey.
kentpachi
Posts: 62
Joined: 15 May 2016, 01:23

Re: playsound and overlay text

28 Jan 2018, 23:03

Exaskryz wrote:Are any actions occuring outside the loop after the soundplay? If you just want to soundplay, then it's fine as is. But if you have other code that you are executing when the image is found, make sure your SoundPlay is set to asynchronous. (Add ,1 after the sound file I believe.)

The point of MsgBox was just to test that AHK is responding speedily to finding the image.

Quick GUI; I suggest you play around with GUI in a separate script to get what you want.

Code: Select all

Gui, Add, Text,,Overlay
Gui, +AlwaysOnTop +E0x20 +LastFound
WinSet, Transparent, 255
Gui, Show, NA, OverlayTitle
return
I learned something new whipping this up for you. I've suggested using +E0x20 for years, but didn't realize (or since forgotten) that you need to make the window transparent for it to work. I did find that a minimum transparency of 255 (the highest numerical value; if it was set to 0, the window would be invisible, so a 255 makes it opaque) is necessary to make it work as a click-through. But you may still want to have it partially transparent, otherwise you wouldn't necessarily know what you're clicking on.

Close the overlay by right clicking on the window icon in the taskbar and selecting close. Otherwise, exit your script, or reload it if you tie the overlay to a hotkey.
thank you

Return to “Ask For Help”

Who is online

Users browsing this forum: flyingDman, Google [Bot], guest3456, Sweetins and 188 guests