Jump to content
Pike

2 Action Button, Single Click vs Double Click

Recommended Posts

Pike

Hello Everyone,

New Guy here. This is a two-part question, hopefully easy enough though. I know it's ugly coding, this is because I have only a couple hours worth of coding experience and could really use some help.

1) When I single click the button I want one action (like playing a sound clip) and when I double click the button I want a different action (such as opening dialogue box to ask for soundclip directory address). At the bottom of the script I made a comment which one I would like single click versus double click.

2) I can not get the FileOpenDialogue to save the file address to the config.ini file at the 'One' position on the .ini.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <FileConstants.au3>
#include <AutoItConstants.au3>
#include <Sound.au3>

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Global $OneID

_Main()

Func _Main()
GUICreate("Form1", 156, 86, 281, 276)
$OneID = GUICtrlCreateButton("Button", 15, 17, 122, 37)
GUICtrlSetOnEvent($OneID, "OnOne")
GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
GUISetState()

While 1
    While 1
        Sleep(1000)
    WEnd
WEnd

EndFunc

;---------------Functions-------------

While 1
    Sleep(100)
 WEnd

Func OnOne()
   ;   ******************Single Click for this action****************
    $OneID = IniRead("config.ini", "Config", "One", $OneID)
    If $OneID = True Then
    SoundPlay($OneID, @HotKeyPressed)
 Else
   ;  *******Double Click for this action*****And Help Saving File Address to config.ini 'One'***********
    $OneID = FileOpenDialog("Select file", @WorkingDir, "All (*.*)")
    IniWrite("config.ini", "Config", "One", $OneID)
    $OneID = InputBox("Enter Information", "Short Name for File?", "")
    IniWrite("config.ini", "Config", "NameOne", $OneID)
    EndIf
 EndFunc

Any help would be greatly appreciated, and if you need anymore clarity as to what exactly I'm trying to do, please do not hesitate to ask. Thanks so much!

Pike

Share this post


Link to post
Share on other sites
KickStarter15

@Pike,

First of all, Welcome to the forum...^_^

Okay... I have this old sample code I just change some of it to our current version. Not sure what you wanted to do with IniWrite() but try experimenting my below code and check if that's what you need.

#include <GUIConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Dim $iTimer = 0, $iClickCount = 0, $CheckTime = 300

$Form1 = GUICreate("Form1", 127, 57, 193, 115)
$OneID = GUICtrlCreateButton("Button", 8, 8, 105, 33, 0)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OneID
            _HandleButton()
    EndSwitch
WEnd


Func _HandleButton()

    $iClickCount += 1
    $iTimer = TimerInit()

    AdlibRegister("CheckButtonPress", $CheckTime)

EndFunc

Func CheckButtonPress()

    If TimerDiff($iTimer) < $CheckTime Or $iTimer = 0 Then Return

    Switch $iClickCount
        Case 1
            MsgBox(0, "Clicked", "Clicked 1 time... Insert your code after this message.")
            ;Insert your code here for sound to play. don't have any sample in my computer right now....
        Case 2
         MsgBox(0, "Clicked", "Clicked 2 times, FileOpenDialog will execute...")
         Local $sFileOpenDialog = FileOpenDialog(0, @ScriptDir & "\", "Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
         If @error Then
         MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.")
         EndIf
;~       IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne", $OneID); not sure what do you want to happened in this part. please explain more and provide details.
    EndSwitch

    $iClickCount = 0
    AdlibUnRegister()

EndFunc

 

Let me know so I can do further assist.^_^

 

KS15


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Pike
Posted (edited)

@KickStarter15

First of all... thank you very much for replying. I'm learning here and it's a bit of curve being thrown at me on this first project. The code you presented is great as far as single versus double clicking on a button. I included some screenshots so you can see what I'm doing.

So when you look at the GUI, each button you see is supposed to play a sound clip designated to it in the config.ini file (when single clicked). If no file path is present in the config.ini then I can double click on the button and it will present a box (FileOpenDialog) so I can choose a file path (D:\Music\randomsong.mp3) to store in the config.ini. Once I do this I should be able to then single click the button and the sound clip would play.

You were asking what I was using the config.ini file for and it's for two things; storing the "TITLE" to display on the button, and storing the filepath for the soundclip (I included a screenshot of the config as well, so maybe to get a better idea).

Your code works great, but when I include my code it just doesn't work.

I don't want to have to go into the config.ini ever. I want to be able to control everything from the GUI. *Single click = SoundPlay... **Double Click = Choose file path for song clip

Here's the code I tried and for some reason it only allows me to perform one action and then the button does nothing. What do you think?

#include <GUIConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Dim $iTimer = 0, $iClickCount = 0, $CheckTime = 300

$Form1 = GUICreate("Form1", 127, 57, 193, 115)
$OneID = GUICtrlCreateButton("Button", 8, 8, 105, 33, 0)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OneID
            _HandleButton()
    EndSwitch
WEnd


Func _HandleButton()

    $iClickCount += 1
    $iTimer = TimerInit()

    AdlibRegister("CheckButtonPress", $CheckTime)

EndFunc

Func CheckButtonPress()

    If TimerDiff($iTimer) < $CheckTime Or $iTimer = 0 Then Return

    Switch $iClickCount
        Case 1
            $OneID = IniRead("config.ini", "Config", "One", $OneID)
               If $OneID = True Then
                  SoundPlay($OneID, @HotKeyPressed)
               EndIf
            ;Insert your code here for sound to play. don't have any sample in my computer right now....
        Case 2
         Local $sFileOpenDialog = FileOpenDialog(0, @ScriptDir & "\", "All (*.*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
            If True Then
               Local $Name1 = InputBox("Enter Information", "Shorthand Name of File?", "")
         EndIf
;~       IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne", $OneID);
         IniWrite(@ScriptDir & "\config.ini", "Config", "One", $sFileOpenDialog)
         IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne", $Name1)
    EndSwitch

    $iClickCount = 0
    AdlibUnRegister()

EndFunc

Thank you for helping again!

Pike

Streaming deck.PNG

config for reading information.PNG

Double Click.PNG

Edited by Pike
@ reply

Share this post


Link to post
Share on other sites
KickStarter15

@Pike,

I added some error checking to see if the functions are working and change some lines of your code.^_^

#include <GUIConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Sound.au3>

Dim $iTimer = 0, $iClickCount = 0, $CheckTime = 300

$Form1 = GUICreate("Form1", 127, 57, 193, 115)
$OneID = GUICtrlCreateButton("Button", 8, 8, 105, 33, 0)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OneID
            _HandleButton()
    EndSwitch
WEnd


Func _HandleButton()

    $iClickCount += 1
    $iTimer = TimerInit()

    AdlibRegister("CheckButtonPress", $CheckTime)

EndFunc

Func CheckButtonPress()

    If TimerDiff($iTimer) < $CheckTime Or $iTimer = 0 Then Return

    Switch $iClickCount
        Case 1
            $SounID = IniRead(@ScriptDir & "\config.ini", "Config", "One", $OneID)

            Local $aSound = _SoundOpen($SounID)
            If @error = 2 Then
               MsgBox($MB_SYSTEMMODAL, "Error", "The file does not exist")
            Exit
            Else
               MsgBox($MB_SYSTEMMODAL, "Success", "The file opened successfully")
            EndIf
            _SoundPlay($SounID)
            _SoundClose($aSound)

        Case 2
         Local $sFileOpenDialog = FileOpenDialog(0, @ScriptDir & "\", "All (*.*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
            If True Then
               Local $Name1 = InputBox("Enter Information", "Shorthand Name of File?", "")
         EndIf
         IniWrite(@ScriptDir & "\config.ini", "Config", "One", $sFileOpenDialog)
         IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne", $Name1)
    EndSwitch

    $iClickCount = 0
    AdlibUnRegister()

EndFunc

Note: Not tested, I don't have any music in my office computer.:sweating:

 

KS15


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Pike

@KickStarter15 

Thank you very much, I ran the script and it works great. I really appreciate the help. I'm going to perform some tweaking to fit my needs, but it's great! 

Take Care,

Pike

Share this post


Link to post
Share on other sites
KickStarter15

Glad to help.^_^


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

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

  • Similar Content

    • AndreasNWWWWW
      By AndreasNWWWWW
      Hi, i'm curious if this is even possible, i want to do an action if the ini file contains current values under a section.
      for my test i'm looking for 100,200,300,400,500
      and if any of those excits i want to pop a msgbox with the number in the section.
      i can in my example find one, but it does not check everyone. why?  what am i missing?
      Local $iscore810[5] = [100,200,300,400,500] Local $iMax800 = 5 While 1 ;~     Send("{pause}") ;;func les ini fil     $var = IniReadSection("Area.ini", "modus")     If @error Then         MsgBox(4096, "Error", "Unable to read section.")     Else          For $number = 1 To $var[0][0] If $var[$number][1] == $iscore810[3] Then       MsgBox($MB_SYSTEMMODAL, "FAnt den på", $var[$number][0], 5) EndIf                       Next     EndIf     exit WEnd  
    • Paxman
      By Paxman
      Just seem to have hit a bit of a hurdle.
      I am trying to get Autoit to tick a box in a dialogue box. However no windows shortcut works (eg. spacebar etc.).
      So having moved to the tick box (how can i produce a double click of the mouse (which ticks the box) without moving the mouse each time. I will need to do this many times in a tall dialogue box you need to scroll through if trying to use the mouse to do it?
      Can i map a keyboard shortcut or something?
      Thanks
      Neil
       
    • PoojaKrishna
      By PoojaKrishna
      Hi friends,
      Is there any way to detect the left double clicks like we get the primary clicks  using _IsPressed("01").
      We can detect double clicks by initiating a timer and finding the delay between left clicks on same coordinates but still want to if there is a better direct way.
      Thank you friends.
       
      #Include <Misc.au3> ; Used for the _IsPressed HotKeySet("{ESC}", "_ExitScript") ;Hot key Esc to Exit script $nCountClick = 0 ;Click Count While 1 ; Loop until user presses ESc to exit the Recorder If _IsPressed("01") then ; If left mouse is pushed. While (_IsPressed("01")) ;Wait until user releases button Sleep(100) WEnd $pos = MouseGetPos() ; Get the position. $nCountClick = $nCountClick + 1 ;Add click count ToolTip($nCountClick & ") " & 'Left Clicked X: ' & $pos[0] & ', Y: ' & $pos[1]) ;Show the click count with position EndIf WEnd Func _ExitScript() ;HotKet method to Exit script Exit EndFunc ;=> _ExitScript  
    • kcvinu
      By kcvinu
      Hi all,
      I have a button created with _GUICtrlButton_Create function. I know that this function returns a handle of button instead of an ID. So i have obtain control ID by calling _WinAPI_GetDlgCtrlID function. After that i have tried the GUICtrlSetBkColor function. But it didnt worked. Any suggestions will be appreciated. Thanks in advance. 
      Note : - The window which carries this button is not created with native gui create function. Instead, it is created with CreateWindowEx api function.
    • kartune
      By kartune
      Hi, i would like to know if there is a possible way to use subsections for ini files?
      For example, my ini file would look something like this:
       
      Clientname.ini
      [Info]
      Country=USA
      Type=Distributor
       
      [Costs]
      [[JAN]] <----- subsection
      cost1=----
      cost2=----
      [[FEB]]
      cost1=----
      cost2=----
       
      [Sales]
      [[JAN]] <----- subsection
      sale1=----
      sale2=----
      [[FEB]]
      sale1=----
      sale2=----
       
      [Profits]
      [[JAN]] <----- subsection
      prof1=----
      prof2=----
      [[FEB]]
      prof1=----
      prof2=----
       
      The sales would be inputed everyday by the script, and then whenever viewed, i would be using an array to view every sale/cost/profit under the subsection
       
       
      Thanks for your time!
×