Pike Posted June 1, 2018 Share Posted June 1, 2018 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. expandcollapse popup#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 Link to comment Share on other sites More sharing options...
KickStarter15 Posted June 2, 2018 Share Posted June 2, 2018 @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. expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Pike Posted June 2, 2018 Author Share Posted June 2, 2018 (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? expandcollapse popup#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 Edited June 2, 2018 by Pike @ reply Link to comment Share on other sites More sharing options...
KickStarter15 Posted June 4, 2018 Share Posted June 4, 2018 @Pike, I added some error checking to see if the functions are working and change some lines of your code. expandcollapse popup#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. Â 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. Link to comment Share on other sites More sharing options...
Pike Posted June 5, 2018 Author Share Posted June 5, 2018 @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 Link to comment Share on other sites More sharing options...
KickStarter15 Posted June 6, 2018 Share Posted June 6, 2018 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now