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 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

    • By Pike
      Hey Everyone, I haven't been here in a while and recently picked up my old project. Still an FNG!
      To the point: I want to be able to push the button and either play an mp3, open a file, or open an exe program (all with the same button). The problem is that I don't know how to code for that at "case 1"
              Case 1                                                                                                                                             
                  Local $sRead = IniRead("config.ini", "Config", "One", "Default")                                
                  SoundPlay($sRead, @HotKeyPressed)                                                                     <-------------------------------
                  Run($sRead, @HotKeyPressed)                                                                                 <------------------------------- This 'Run' doesn't work even by itself!
      See code below for layout. If you need more information I will attach more code or answer any questions. Any help is greatly appreciated.
       
      Much Respect,
      Pike
       
      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 Local $sRead = IniRead("config.ini", "Config", "One", "Default") SoundPlay($sRead, @HotKeyPressed) Run($sRead, @HotKeyPressed) Case 2 MsgBox(0, "INFORMATION:", "Choose the file you want designated to this button") Local $sFileOpenDialog = FileOpenDialog(0, @ScriptDir & "\", "All (*.*)", $FD_FILEMUSTEXIST + $FD_MULTISELECT) If @error Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.") EndIf Local $sFileName = InputBox("INFORMATION:", "Please Name Your File?" & @CRLF _ & @CRLF _ & "6 Characters or Less", "") IniWrite(@ScriptDir & "\config.ini", "Config", "One", $sFileOpenDialog) IniWrite(@ScriptDir & "\config.ini", "Config", "NameOne", $sFileName) EndSwitch $iClickCount = 0 AdlibUnRegister() EndFunc  

    • By XinYoung
      Greetings!
      I am in need of your guidance once again. I searched the forums for clicking in span, clicking by class, clicking without an ID or Name, etc., but I am unable to find a solution for my problem.
      I am trying to expand this tree in IE. There is an arrow ( > ) that i need to click, but I can't find a way to do it . Alternatively, I can double-click the text "Servers", but that seems to be even more troublesome. I will have to do this 2-3 more times as the tree expands.
      There appears to be an ID for the tree, simply called "tree", but that isn't working when I send a click to it.

      ;Open an IE session and navigate to pgAdmin. Global $oIE = _IECreate($pgAdmin) ;Maximize the IE window. WinSetState(_IEPropertyGet($oIE, "hwnd"), "", @SW_MAXIMIZE) Sleep(2000) ;Expand the tree $oTree = _IEGetObjById($oIE, "tree") _IEAction($oTree, "click") Any ideas?  
    • By misioooo
      Hi!
       
      I am writing some GUI and i need to use images as buttons, but with text on them (text is from INI file).
      Part with button looks like this:
      $ankieta1 = GUICtrlCreateButton($txtAnk1, 100,350,765,164) GUICtrlSetFont(-1, 22, 800, -1, "Arial") ;GUICtrlSetColor(-1,0xffffff) $hImageBtn_1 = _GUIImageList_Create(765, 164) _GUIImageList_AddBitmap($hImageBtn_1, "c:\path\to\ankieta_clean.bmp") _GUICtrlButton_SetImageList($ankieta1, $hImageBtn_1, 4) GUICtrlSetOnEvent(-1, "On_Ankieta1") The problem - if i uncomment GUICtrlSetColor, color of text changes, but button is just plain gray (no image). How i can change text color not touching image on a button here?
    • By XinYoung
      Quick question: How can I click this "Select All" button in IE? There's no ID, and the href is "#"  
      Am I looking at the wrong html code?
      Am I looking
      Thank you all in advance!
×
×
  • Create New...