pneumatic wrote:edit: tested it out and it seems to work fine. I just don't understand it , read it about 10 times and my brain is refusing
Every time the slider's g-label is called If the reason is 4 or Normal ( Mouse release or at the end of any other reason is always a repeated normal ) it will run your update one last time, and soundplay. Otherwise it will watch the slider and update whenever it's value changes.
I can see how if you have more than one slider, and you need to do something different depending on which slider is being moved, can complicate things, but what solution do you already use for that? I will try to get a sample version working with two different sliders and see if I can help with that.
Edit:
I have an example for using two sliders and doing something different with each:
Code: Select all
#Persistent
#SingleInstance Force
SetBatchLines , -1
DllCall("QueryPerformanceCounter", "Int64*", CounterBefore)
Sleep 1000
DllCall("QueryPerformanceCounter", "Int64*", CounterAfter)
Global 1ms := (CounterAfter - CounterBefore) / 1000
Gui, 1:New
Gui, Add, Slider, ToolTip AltSubmit x10 y10 w720 Range-35-35 vSlider1 gSliderG ; Note all sliders point to same g-label
Gui, Add, Slider, ToolTip AltSubmit x10 y50 w720 Range-35-35 vSlider2 gSliderG
Gui, Add, Text, vaText w250 x300 yp+50
Gui, Show, y200 w740 h150, Slider Test (Window 1)
Gui, 2:New
Gui, Add, Slider, ToolTip AltSubmit x10 y10 w720 Range-35-35 vSlider1 gSliderG ; Note all sliders point to same g-label
Gui, Add, Slider, ToolTip AltSubmit x10 y50 w720 Range-35-35 vSlider2 gSliderG
Gui, Add, Text, vaText w250 x300 yp+50
Gui, Show, y400 w740 h150, Slider Test (Window 2)
Return
SliderG:
IF (!IsObject(useFunction))
useFunction := Func("watchSlider").Bind(A_Gui, A_GuiControl) ; Only way I know how to use setimer on a function with parameters. Doesn't work if you keep overwriting the binding, so only do it if the binding doesn't already exist.
IF (A_GuiEvent = 4 || A_GuiEvent = "Normal") {
SetTimer, % useFunction, -1 ; -1 instead of Off to have it update on the final position.
AlreadyWatching := False
useFunction := "" ; Clear the function Binding.
Soundplay , *64
}
Else IF !(AlreadyWatching) {
SetTimer, % useFunction, 1
AlreadyWatching := True
}
Return
watchSlider(guiName, controlSlide) {
Static prevVal
Gui, %guiName%:Default
GuiControlGet, sliderVal,, %controlSlide%
IF (sliderVal != prevVal) {
IF (controlSlide = "Slider1") { ; Put whatever you use to differentiate different sliders here using controlSlide
DllCall("QueryPerformanceCounter", "Int64*", CounterBefore)
counter := 0
loop 1500000
{
counter += 1
}
DllCall("QueryPerformanceCounter", "Int64*", CounterAfter)
GuiControl,, aText, % "Subroutine duration: " . Round(((CounterAfter - CounterBefore) / 1ms)) . "ms"
prevVal := sliderVal
ToolTip, %sliderVal% ; Just an example, to show how to use the current value of the slider, without needing to submit the GUI.
}
Else IF (controlSlide = "Slider2") {
ToolTip, You're Moving Slider 2 of GUI:%guiName%
}
}
Return
}
Edit: Updated to make prevVal static, and showing how it works with 2 separate GUIs.