Jump to content

ComboBox to set function


Trent
 Share

Recommended Posts

#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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Trent,

Glad I could help. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...