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

    • nooneclose
      By nooneclose
      Hello again, I am in phase two of my help bot. I cannot figure out how to properly code Autoit to click on a webpage button using the I.E UDF. I want to click on the button that I have attached as an image. This button does not have a name but it has an ID. Here is the HTML code for this button that I found using chromes developer inspector.
      HTML Code: 
      <img role="button" tabindex="-1" id="toolactions_INSERT-tbb_image" src="nav_icon_insertkey.gif" alt="New Work Order CTRL+ALT+I" draggable="false"> Here is the code that I have so far:
      ;******************************************************************************* ; Opens IE and fill out a New Workorder ;******************************************************************************* ; Start IE at the ** Tracking Application in ****** $oIE = _IECreate("https:I_am_Bound_by_my_company_to_not_reveal_this_webpage") ; Wait for a browser page load to complete _IELoadWait($oIE) Sleep(6000) ; Store the field names where the important data will be sent Local $nWorkOrderB = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image") _IEAction($nWorkOrderB, "click")  I want my program to click on the button that looks like a piece of paper with a blue # 
      (For those wondering, I am allowed to send images just not the URL.) 
      As always any help would be appreciated. 

    • MJ36
      By MJ36

      How to click this button ? 
      I Try 
       
      func test () $oCorrectObj = "" $tags = $oIE.document.GetElementsByTagName("button") For $tag in $tags $class_value = $tag.GetAttribute("type") If string($class_value) = "buttont" Then $oCorrectObj = $tag MsgBox(0, "Level: ", "Level found :)") Else MsgBox(16, "Failed", "Not found.") ExitLoop EndIf Next If IsObj ( $oCorrectObj ) Then _IEAction ($oCorrectObj, "click") EndIF  
      and
       
      func klik () Local $oFound = "" Local $oBtns = _IETagNameGetCollection($oIE, "span") For $oBtn In $oBtns If String($oBtn.classname) = "yt-uix-button-content" Then $oFound = $oBtn EndIf Next _IEAction ($oFound, "click") EndFunc  
      Please Help 
      Can you click it by name?
    • faustf
      By faustf
      i guys , like title anyone  have idea if is possible , and if yes if  have example to post ?  i find in forum and in google but  i dont know   how can start  to create  button with icon over toolbar near  clock or is  goog before language layout .
      sorry i not post any script but i dont know  where to start
      thankz
      at  all
    • caramen
      By caramen
      Hmmm i am sorry  i had simular problem but i cant find back post. 
       
      How to hide a gui button ? 
       
      I Want to dodge the variable non déclaréd when i make button in
      if statment 
       
      thx before 
×