Jump to content

Trying to set a hotkey as the selected item in combo box


 Share

Recommended Posts

Ok so what I'm trying to do, is get this program to allow the user to select what he/she wants the hot key to be set as. Then pressing the key will execute the function. I want it so that you can go back and change the key too.

Also, this is just for one hot key and function, I want it to be able to do multiple functions at the same time. Is it possible to make it run multiple functions and still have the hot keys to enable/disable the functions? Like the stuff in the function would be in a infinite loop until it is pressed again.

Sorry if this is confusing, this is my first program I've tried to make with GUI's lol.

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>

Opt('MustDeclareVars', 1)

Global $KeySelect
Global $TheKey
    
; Create GUI
GUICreate("ComboBox Add String", 400, 296)
$KeySelect = GuiCtrlCreatecombo("", 51, 1, 53, 15)
GUISetState()

While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

; Add string
_GUICtrlComboBox_AddString($KeySelect, " ")
_GUICtrlComboBox_AddString($KeySelect, "5")
_GUICtrlComboBox_AddString($KeySelect, "6")
_GUICtrlComboBox_AddString($KeySelect, "8")
_GUICtrlComboBox_AddString($KeySelect, "9")
_GUICtrlComboBox_AddString($KeySelect, "0")
_GUICtrlComboBox_AddString($KeySelect, "-")
_GUICtrlComboBox_AddString($KeySelect, "=")

$TheKey = _GUICtrlComboBox_GetCurSel($KeySelect);Set the variable to the selected box

HotKeySet($TheKey, "ShowSelected")
    
Func ShowSelected()
    MsgBox(4160, "Information", "Cur Sel: " & ($TheKey))
EndFunc
Link to comment
Share on other sites

  • Moderators

gainstaa,

I think this does what you want:

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <Constants.au3>

Opt('MustDeclareVars', 1)

Global $KeySelect
Global $TheKey = ""
Global $KeyList = "|5|6|7|8|9|0|-|="

; Create GUI
GUICreate("ComboBox Add String", 400, 300)

$KeySelect = GuiCtrlCreatecombo("", 50, 10, 50, 20)
GUICtrlSetData(-1, $KeyList)

GUISetState()

While 1

    If GuiGetMsg() = $GUI_EVENT_CLOSE Then Exit

    ; See if the combo selection has changed AND the combo is closed
    If GUICtrlRead($KeySelect) <> $TheKey And _GUICtrlComboBox_GetDroppedState($KeySelect) = False Then

        ; Check the entered value is in the list
        If StringInStr($KeyList, GUICtrlRead($KeySelect)) > 0 Then

            $TheKey = GUICtrlRead($KeySelect)
            HotKeySet($TheKey, "ShowSelected")

        Else

            MsgBox(0, "Error", "Please enter a valid key" & @CRLF & "0, 5-9, - or =" )
            GUICtrlSetData($KeySelect, $KeyList, $TheKey)

        EndIf

    EndIf

WEnd

Func ShowSelected()
    MsgBox(4160, "Information", "Cur Sel: " & ($TheKey))
EndFunc

Please ask if anything is unclear. :D

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

Perfect. :D

But now I am facing two other problems. Firstly, if I set the box to 5 say, then change it to 6 later, it is still registering it as 5 AND 6. So I need a way to clear the previous hotkey or something.

Secondly, when I made another combo box using F1-F8 keys, it is causing a mistake. It will eventually get the 'F' Key to work, but only after several tries usually. And when I run it in notepad, it actually types out "F2" or which ever 'F' Key I used. I'm not sure if it has something to do with it being a string value in the combo box, or if the mistake is in my Send command.

The combo box code for the F1-F8 keys:

If GuiGetMsg() = $GUI_EVENT_CLOSE Then Exit
    ; See if the combo selection has changed AND the combo is closed
    If GUICtrlRead($KeySelect3) <> $TheKey3 And _GUICtrlComboBox_GetDroppedState($KeySelect3) = False Then
        ; Check the entered value is in the list
        If StringInStr($KeyList3, GUICtrlRead($KeySelect3)) > 0 Then
            $TheKey3 = GUICtrlRead($KeySelect3)
        Else
            MsgBox(0, "Error", "Please enter a valid key" & @CRLF & "F1-F8" )
            GUICtrlSetData($KeySelect3, $KeyList3, $TheKey3)
        EndIf
    EndIf

The Send:

Send("{" & $TheKey3 & " down" & "}")
Edited by gainstaa
Link to comment
Share on other sites

  • Moderators

gainstaa,

I need a way to clear the previous hotkey or something

And what have you tried yourself? :D

To unset the HotKey before setting the new one just add this line:

; Check the entered value is in the list
If StringInStr($KeyList, GUICtrlRead($KeySelect)) > 0 Then

    HotKeySet($TheKey) ; <<<<<<<<<<<<<<<<<<<<<<<<<< Unset current hotkey
    $TheKey = GUICtrlRead($KeySelect)
    HotKeySet($TheKey, "ShowSelected")

Else

As for the problem with Sending the F keys, I have no idea why it is not working -the syntax seems correct.

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

gainstaa,

And what have you tried yourself? :D

To unset the HotKey before setting the new one just add this line:

; Check the entered value is in the list
If StringInStr($KeyList, GUICtrlRead($KeySelect)) > 0 Then

    HotKeySet($TheKey) ; <<<<<<<<<<<<<<<<<<<<<<<<<< Unset current hotkey
    $TheKey = GUICtrlRead($KeySelect)
    HotKeySet($TheKey, "ShowSelected")

Else

As for the problem with Sending the F keys, I have no idea why it is not working -the syntax seems correct.

M23

Well I just tried searching here on forums, and in the help file about deleting a hotkey, clearing, removing, etc. lol

Thank you for the help, any way I could give you some Karma or anything? :huggles:

Link to comment
Share on other sites

  • Moderators

gainstaa,

any way I could give you some Karma or anything?

Thank you for the very kind offer, :D but....

[serious for a moment]

if you really want to give something, I would rather you gave it to the Haiti relief fund.

[/serious for a moment]

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