Jump to content
Pike

2 Action Button, Single Click vs Double Click

Recommended Posts

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

@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

@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

@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

@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

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

    • By nacerbaaziz
      good morning sirs.
      please i have a request from you.
      i have an variable to Read a data from a file
      this data is Encrypted
      and when i read it i Decrypte it.
      for that i need a function to Write a ini data to string.
      ;#Function# ===================================================================================================================== ; Name............: _IniReadFromString ; Description.....: Returns the value of a key in a specific section of an ini-formatted string ; Syntax..........: _IniReadFromString($szInput, $szSection, $szKey, $Default) ; Parameters......: ;   $szInput - The string that contains data in ini format ;   $szSection   - The sectionname (just as in IniRead) ;   $szKey   - The keyname (just as in IniRead) ;   $Default - The default value if the key does not exist or reading failed (just as in IniRead) ; Return values ..: ;   Success  - Returns the read value ;   Failure  - Returns $Default ; Author .........: FichteFoll ; Remarks ........: Works for Unicode as well as for ANSI ; Related ........: IniRead, _IniReadSectionFromString ; Link ...........; See on top ; Example ........; $var = _IniReadFromString(StringFormat("[Sect]\r\nMyKey1=value1\r\nMyKey2=value2"), "Sect", "MyKey2", "no_value") ; =============================================================================================================================== Func _IniReadFromString($szInput, $szSection, $szKey, $Default) $szInput = StringStripCR($szInput) ;~  Local $aRegMl = StringRegExp($szInput, "\[" & __StringEscapeRegExp($szSection) & "\]\n+(?:[^\[].*?=.*\n)*" & __StringEscapeRegExp($szKey) & "=(.*)\n?(",3) Local $aRegMl = StringRegExp($szInput, "\[" & __StringEscapeRegExp($szSection) & "\]\n+(?:[^\[].*?=.*\n)*" & __StringEscapeRegExp($szKey) & "=(.*)\n?", 3) If @error Then Return SetError(1, 0, $Default) ; key not found    Return $aRegMl[0] EndFunc;==>_IniReadFromString ; ############################################################################################################################### ; =============================================== ; = Internal Use Only ; =============================================== Func __StringEscapeRegExp($szExp) Return StringRegExpReplace($szExp, "([\(\)\[\]\{\}\\\/\?\.\\|\+])", "\\$1") ; ()[]{}\/?.|+ EndFunc;==>__StringEscapeRegExp like this  function Read the ini from string.
       
       
      please ihelp me
      thanks in advance
    • By nacerbaaziz
      good morning all.
      first lit me give you all a thinks to your help
      you're help me allot thank you all.
      sirs today i've a new problem
      it's not a problem but thing i want to add it to blind accessability.
      the ListBox can send a notification when the user send a double click on it items
      but as we know that the blind users can't use the mouse for that they use the keybord to navigate.
      as we know that the enter replace the double click on the keybord
      for that i need when the user send a inter above any listBox item the list send a double click notification.
      i know some of you tell me that i can use the  GUISetAccelerators function
      but the enter has a other tasks such as leav a blanc line on edits and activate the defaultButton and other tasks.
      that what i need and i hope that you can help me
      this is a simple example.
      #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Example() Func Example() Local $sMESSAGE = "The following buttons have been clicked" GUICreate("My GUI list") ; will create a dialog box that when displayed is centered Local $idButton_Add = GUICtrlCreateButton("Add", 64, 32, 75, 25) Local $idButton_Clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25) global $idMylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 121, 97) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUICtrlSetData(-1, $sMESSAGE) global $DummyList = GUICtrlCreateDummy() GUICtrlSendToDummy($DummyList, 1) Local $idButton_Close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25) GUIRegisterMsg($WM_command, "WM_command") GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton_Add GUICtrlSetData($idMylist, "You clicked button No1|") Case $idButton_Clear GUICtrlSetData($idMylist, "") Case $idButton_Close MsgBox($MB_SYSTEMMODAL, "", "the closing button has been clicked", 2) Exit case $DummyList $g_iTemp = GUICtrlRead($DummyList) if $g_iTemp = $LBN_DBLCLK then ;$LBN_DBLCLK then msgBox(64, "", "") endIf GUICtrlSendToDummy($DummyList, 0) EndSwitch WEnd EndFunc ;==>Example Func WM_command($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = $lParam $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case GUICtrlGetHandle($idMylist) Switch $iCode Case $LBN_SELCHANGE, $LBN_DBLCLK, $LBN_SELCANCEL, $LBN_SETFOCUS GUICtrlSendToDummy($DummyList, $iCode) case else ;GUICtrlSendToDummy($DummyTreeview, 1) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc  
    • By _leo_
      Hey there!
      I am having a problem with clicking a button in IE. As you can see in the code, there would be a class name to click it, but since this button exists several times with exactly the same code, I can only use the "Noch nicht veröffentlicht" to separate it from the others. But this part is just pure text without any classification. 
      "<div class="checkmark" data-v-1e5b1f70=""><svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 16 16" data-v-1e5b1f70=""><circle cx="8" cy="8" r="8" data-v-1e5b1f70="" /></svg></div>Noch nicht veröffentlicht"
      I was trying to click it with:
      #include <IE.au3> local $oNNVs = _IEFormGetCollection($oIE2) For $oNNV in $oNNVs If String($oNNV.innertext) = "Noch nicht veröffentlicht" Then _IEAction($oNNV, "click") EndIf Next and:
      $inputs = $oIE2.document.getElementsByTagName("div") For $input In $inputs If $input.innertext == "Noch nicht veröffentlicht" then $input.click() EndIf Next But nothing seems to work. Thanks for the help!
    • By nacerbaaziz
      hello sirs,
      i have searched allot about an function that can  read the INI file as a  string
      i mean function to read the ini files from string and not from the file directly.
      i finally found an UDF that do what i want
      but unfortunately all the functions work,  but the function that i want it not working.
      this is the udf
      the function that  i need is _IniReadFromString
      this is the function

      Func _IniReadFromString($szInput, $szSection, $szKey, $Default) $szInput = StringStripCR($szInput) Local $aRegMl = StringRegExp($szInput, "\[" & __StringEscapeRegExp($szSection) & "\]\n+(?:[^\[].*?=.*\n)*" & __StringEscapeRegExp($szKey) & "=(.*)\n?(", 3) If @error Then Return SetError(1, 0, $Default) ; key not found Return $aRegMl[0] EndFunc;==>_IniReadFromString
      i hope that any one can help me
      thank you in advance
      iniex.au3
    • By GillesMaisonneuve
      Good morning,
       
      I am trying to align a two-line text in a button so that it would be centered in the button but can't succeed to do it for the vertical part.
      Can someone tell me what I do wrong ?
      Here is my code:
      $btn3 = GUICtrlCreateButton("Execute " & @LF & " file 1", 100, 65, 60, 50, _ BitOr($BS_CENTER,$BS_BOTTOM,$BS_MULTILINE)) and here is the resulting layout I get in my window.
      I tried to follow the help, made a lot of different parameter combinations (here it's `$BS_BOTTOM`, but I tried `$BS_VCENTER` and `$BS_TOP`), still get the same result : vertical alignement is a no go for me.
      Can someone help ?
      TIA
      Gilles

×
×
  • Create New...