Sign in to follow this  
Followers 0
Trent

ComboBox to set function

4 posts in this topic

#1 ·  Posted (edited)

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 625, 445, 192, 124)
$Combo1 = GUICtrlCreateCombo("Select Bind", 120, 128, 145, 25)
GUICtrlSetData(-1, $Combo1)
$Button1 = GUICtrlCreateButton("Set", 144, 184, 75, 25, $WS_GROUP)
$Button1 = GUICtrlCreateButton("Load", 190, 210, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Global $Combo1 = "|1|2|3|4|5"


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
Case $GUI_EVENT_CLOSE
    Exit
Case $Button1
    SAVEINI()
    EndSwitch
WEnd

HotKeySet( $Combo1 , "MSG")

Func MSG()
    msgbox(0,"Test","Working")
EndFunc

func SAVEINI()
    IniWrite(@ScriptDir & "\settings.ini", "CONFIGURATION", "Hotkey", $Combo1)
EndFunc

func LOADINI()
    $Combo1 = IniRead(@ScriptDir & "\settings.ini", "CONFIGURATION", "Hotkey", 1)
EndFunc

Right now I'm trying to use a ComboBox to set a hotkey to a function. What I want the program to do is the user selects the hotkey from a list in the combobox then presses button1. Which then writes the hotkey he selected to settings.ini. When the user presses button2 it will then load the hotkey from settings.ini.

I already know I'm doing something wrong with the variables. It would be greatly appreciated if someone could help me out on this ;).

Thanks

edit : I meant to put the title as " ComboBox to set hotkey to a function " Sorry about that.

Edited by Trent

Share this post


Link to post
Share on other sites



Trent,

Welcome to the AutoIt forum. ;)

This should give you an idea of how to go about it:

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Form1", 625, 445, 192, 124)
GUICtrlCreateLabel("Select Bind", 120, 108, 145, 15) ; <<<<<<<<<<<<<<<<<<<<<<<<<<< Or it always appears as a Combo option
$Combo1 = GUICtrlCreateCombo("", 120, 128, 145, 25)
;GUICtrlSetData(-1, $Combo1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< What is this supposed to do?
$Button1 = GUICtrlCreateButton("Set", 144, 184, 75, 25)
$Button2 = GUICtrlCreateButton("Load", 190, 210, 75, 25) ; <<<<<<<<<< You need unique variable names
GUISetState(@SW_SHOW)

GUICtrlSetData($Combo1, "|1|2|3|4|5") ; Set the values in the combo

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            SAVEINI()
            HotKeySet("1") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Unset a previous hotkey
            HotKeySet("2")
            HotKeySet("3")
            HotKeySet("4")
            HotKeySet("5")
            HotKeySet(GUICtrlRead($Combo1), "MSG") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< And set the one you have just chosen
        Case $Button2
            LOADINI()
    EndSwitch
WEnd

HotKeySet($Combo1, "MSG") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< This never gets actioned as it is after the infinite loop

Func MSG()
    MsgBox(0, "Test", "Working")
EndFunc   ;==>MSG

Func SAVEINI()
    IniWrite(@ScriptDir & "\settings.ini", "CONFIGURATION", "Hotkey", GUICtrlRead($Combo1))
EndFunc   ;==>SAVEINI

Func LOADINI()
    $sKey =IniRead(@ScriptDir & "\settings.ini", "CONFIGURATION", "Hotkey", 1) ; Set the saved HotKey (default = 1)
    HotKeySet($sKey, "MSG")
EndFunc   ;==>LOADINI

Please ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Ah, now I see what I should of done.

Thanks a lot! ;)

Share this post


Link to post
Share on other sites

Trent,

Glad I could help. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
Sign in to follow this  
Followers 0