Sign in to follow this  
Followers 0
Klovis

Mouse Down on Button Counter

8 posts in this topic

I want to hold down $Button1 and every second I hold it down it adds 1000 to $d and when I have a mouseup occur it should play the beep. But I don't know what is wrong, can someone point me in the right direction

-Klovis

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $f
Global $d

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Beep", 173, 104, 192, 114)
$Slider1 = GUICtrlCreateSlider(8, 24, 158, 45)
$hSlider = GUICtrlGetHandle($Slider1)
$Label1 = GUICtrlCreateLabel("0%", 72, 0, 24, 17)
$Button1 = GUICtrlCreateButton("Beep", 48, 72, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_HSCROLL, "hscroll")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If MouseDown("left") Then
                If @SEC = @SEC + 1 Then
                    Do
                        $d = $d + 1000
                    Until MouseUp("left")
                EndIf
            EndIf
            _WinAPI_Beep($f, $d)
            If MouseUp("left") Then $d = 0
    EndSwitch
WEnd

Func hscroll($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref
    Local $f
    If $ilParam = $hSlider Then
        $f = GUICtrlRead($Slider1)
        GUICtrlSetData($Label1, (Number($f)/2000 * 2000) & "%")
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc

Share this post


Link to post
Share on other sites



I want to hold down $Button1 and every second I hold it down it adds 1000 to $d and when I have a mouseup occur it should play the beep. But I don't know what is wrong, can someone point me in the right direction

-Klovis

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $f
Global $d

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Beep", 173, 104, 192, 114)
$Slider1 = GUICtrlCreateSlider(8, 24, 158, 45)
$hSlider = GUICtrlGetHandle($Slider1)
$Label1 = GUICtrlCreateLabel("0%", 72, 0, 24, 17)
$Button1 = GUICtrlCreateButton("Beep", 48, 72, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_HSCROLL, "hscroll")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If MouseDown("left") Then
                If @SEC = @SEC + 1 Then
                    Do
                        $d = $d + 1000
                    Until MouseUp("left")
                EndIf
            EndIf
            _WinAPI_Beep($f, $d)
            If MouseUp("left") Then $d = 0
    EndSwitch
WEnd

Func hscroll($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref
    Local $f
    If $ilParam = $hSlider Then
        $f = GUICtrlRead($Slider1)
        GUICtrlSetData($Label1, (Number($f)/2000 * 2000) & "%")
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc

MouseDown will actually press the Mouse Button.

Try:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
$dll = DllOpen("user32.dll")

Global $f = 500
Global $d

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Beep", 173, 104, 192, 114)
$Slider1 = GUICtrlCreateSlider(8, 24, 158, 45)
$hSlider = GUICtrlGetHandle($Slider1)
$Label1 = GUICtrlCreateLabel("0%", 72, 0, 24, 17)
$Button1 = GUICtrlCreateButton("Beep", 48, 72, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_HSCROLL, "hscroll")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $Button1

    EndSwitch
    If _IsPressed("01", $dll) Then
        Do
            $d = $d + 10
            Sleep(10)
        Until Not _IsPressed("01", $dll)
        _WinAPI_Beep($f, $d)
        $d = 0
    EndIf
Sleep(13)
WEnd

Func hscroll($hWnd, $iMsg, $iwParam, $ilParam)

    Local $f
    If $ilParam = $hSlider Then
        $f = GUICtrlRead($Slider1)
        GUICtrlSetData($Label1, (Number($f) / 2000 * 2000) & "%")
    EndIf
    Return "GUI_RUNDEFMSG"

EndFunc   ;==>hscroll

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

So can you explain to me some of this stuff so I'm not completly just copy pasta. Why:

is the endswitch in the case $button

did you set $f to local and have the global $f and the global is set to 50? the slider is supposed to take care of all the frequencys.

you know stuff like that

Edit: Tried it out and it is really buggy like it's not holding the button it's just when the button is down so if you hold the slider its like beeeeeeeeeeep I want to hold the button and then either during or after it will make the beep.

Edited by Klovis

Share this post


Link to post
Share on other sites

So can you explain to me some of this stuff so I'm not completly just copy pasta. Why:

is the endswitch in the case $button

did you set $f to local and have the global $f and the global is set to 50? the slider is supposed to take care of all the frequencys.

you know stuff like that

I did not consentrate on the sound so there was some left overs.

The slider will now controll the frequency.

Some More Notes are inside:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
$dll = DllOpen("user32.dll")

Global $f = 500; This is just to have a value don't need the value
Global $d

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Beep", 173, 104, 192, 114)
$Slider1 = GUICtrlCreateSlider(8, 24, 158, 45)
$hSlider = GUICtrlGetHandle($Slider1)
$Label1 = GUICtrlCreateLabel("0%", 72, 0, 24, 17)
$Button1 = GUICtrlCreateButton("Beep", 48, 72, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_HSCROLL, "hscroll")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $Button1; Left this from your script. It seems to interfere with "Left Buton" click
                     ; That is why I took it away from this Case
MsgBox(0, '', 'Button', .3)
    EndSwitch
    If _IsPressed("01", $dll) Then
        Do
            $d = $d + 10
            Sleep(10)
        Until Not _IsPressed("01", $dll)
        _WinAPI_Beep($f, $d)
        $d = 0
    EndIf
Sleep(13)
WEnd

Func hscroll($hWnd, $iMsg, $iwParam, $ilParam)
; Removed the Local $f so that it is available in all functions
    If $ilParam = $hSlider Then
        $f = GUICtrlRead($Slider1)
        GUICtrlSetData($Label1, (Number($f) / 2000 * 2000) & "%")
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>hscroll

Share this post


Link to post
Share on other sites

I did not consentrate on the sound so there was some left overs.

The slider will now controll the frequency.

Some More Notes are inside:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
$dll = DllOpen("user32.dll")

Global $f = 500; This is just to have a value don't need the value
Global $d

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Beep", 173, 104, 192, 114)
$Slider1 = GUICtrlCreateSlider(8, 24, 158, 45)
$hSlider = GUICtrlGetHandle($Slider1)
$Label1 = GUICtrlCreateLabel("0%", 72, 0, 24, 17)
$Button1 = GUICtrlCreateButton("Beep", 48, 72, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_HSCROLL, "hscroll")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            DllClose($dll)
            Exit
        Case $Button1; Left this from your script. It seems to interfere with "Left Buton" click
                     ; That is why I took it away from this Case
MsgBox(0, '', 'Button', .3)
    EndSwitch
    If _IsPressed("01", $dll) Then
        Do
            $d = $d + 10
            Sleep(10)
        Until Not _IsPressed("01", $dll)
        _WinAPI_Beep($f, $d)
        $d = 0
    EndIf
Sleep(13)
WEnd

Func hscroll($hWnd, $iMsg, $iwParam, $ilParam)
; Removed the Local $f so that it is available in all functions
    If $ilParam = $hSlider Then
        $f = GUICtrlRead($Slider1)
        GUICtrlSetData($Label1, (Number($f) / 2000 * 2000) & "%")
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>hscroll

K well the thing is that when I click on the slider it will start the timer for the beep I just want it so that when I click the button it will beep ya know?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

K well the thing is that when I click on the slider it will start the timer for the beep I just want it so that when I click the button it will beep ya know?

K. I C.

I thought the slider is the frequency so I left it as that. So now it'll beep for as long as you kept the Button in as per the OP.

See if you like this version then?

[code]#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
Opt("GUIOnEventMode", 1)
$dll = DllOpen("user32.dll")
Global $f
Global $d
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Beep", 173, 104, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "TheExit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "MyBeepA")
$Slider1 = GUICtrlCreateSlider(8, 24, 158, 45)
$hSlider = GUICtrlGetHandle($Slider1)
$Label1 = GUICtrlCreateLabel("0%", 72, 0, 24, 17)
$Button1 = GUICtrlCreateButton("Beep", 48, 72, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_HSCROLL, "hscroll")
While 1
    Sleep(13)
WEnd
Func hscroll($hWnd, $iMsg, $iwParam, $ilParam)
    If $ilParam = $hSlider Then
        $f = GUICtrlRead($Slider1)
        GUICtrlSetData($Label1, (Number($f) / 2000 * 2000) & "%")
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>hscroll

Func MyBeepA()
    While Sleep(10) * _IsPressed("01", $dll)
        $aCurs = GUIGetCursorInfo()
        If $aCurs[4] <> $Button1 Then ExitLoop
        $d += 10
    WEnd
    _WinAPI_Beep($f, $d)
    $d = 0
EndFunc   ;==>MyBeepA
Func TheExit()
     DllClose($dll)
    Exit
EndFunc   ;==>TheExit

Some cleaning up.

Edited by JoHanatCent

Share this post


Link to post
Share on other sites

not hearing anything...

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

not hearing anything...

Strange!

First thing is to slide the slider to say 70% then

press the Button for the duration that you need

as soon as you release the button it will make the sound.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
Opt("GUIOnEventMode", 1)
$dll = DllOpen("user32.dll")
Global $f = 500; Added a start value else it will start with 0
Global $d
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Beep", 173, 104, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "TheExit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "MyBeepA")
$Slider1 = GUICtrlCreateSlider(8, 24, 158, 45)
GUICtrlSetLimit(-1, 100, 0)
GUICtrlSetData($Slider1, Number(45))
$hSlider = GUICtrlGetHandle($Slider1)
$Label1 = GUICtrlCreateLabel("45%", 72, 0, 24, 17)
$Label2 = GUICtrlCreateLabel("0", 100, 0, 24, 17)
$Button1 = GUICtrlCreateButton("Beep", 48, 72, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
GUIRegisterMsg($WM_HSCROLL, "hscroll")
While 1
    Sleep(13)
WEnd
Func hscroll($hWnd, $iMsg, $iwParam, $ilParam)
    If $ilParam = $hSlider Then
        $f = GUICtrlRead($Slider1)
        GUICtrlSetData($Label1, (Number($f) / 2000 * 2000) & "%")
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>hscroll

Func MyBeepA()
    While Sleep(10) * _IsPressed("01", $dll)
        $aCurs = GUIGetCursorInfo()
        If $aCurs[4] <> $Button1 Then ExitLoop
        $d += 10
        GUICtrlSetData($Label2, $d)
    WEnd
    _WinAPI_Beep($f, $d)

    $d = 0
    GUICtrlSetData($Label2, 'Count')
EndFunc   ;==>MyBeepA
Func TheExit()
    DllClose($dll)
    Exit
EndFunc   ;==>TheExit

Added spoiler

Edited by JoHanatCent

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0