Sign in to follow this  
Followers 0
Holepater

[Question] how to link function to selected combobox

6 posts in this topic

Hi,

I'm quitte new to AutoIT and this is my first project but im now stuck.

I've tried several options.

What i wanna do is, i have 3 options in my combobox and i wanna link each of one on the right Function  and all of them executed with a hotkey.

For example i selected Combo4 in the combobox i wanna execute Func Combo4 with hotkey F5

tried several things on different ways but never really working.

Thanks so far 

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>


Global $Combo2

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 433, 280, 192, 124)

;;;;;;;;;;;;;;;;;;;;;;;
$Label2 = GUICtrlCreateLabel("Combo", 296, 56, 55, 17)
$Combo2 = GUICtrlCreateCombo("", 264, 88, 121, 25)
GUICtrlSetData($Combo2, "Combo3 |Combo4 |Combo5", "Combo3")
;//////////////;

#EndRegion ### END Koda GUI section ###



GUISetState(@SW_SHOW)

;hotkeys
hotkeyset("{F5}", "$Combo2")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Func
Func Combo3 ()
Send("{Tab}")
sleep(1)
send("w")
sleep(1)
Mouseclick("left")
sleep(1)
Send("{tab}")
sleep(1)
Send("w")
sleep(1)
MouseClick ("left")
sleep(1)
Send("{TaB}")
sleep(1200)
send("z")
Sleep(1)
mouseclick("left")
EndFunc

Func Combo4()
Send("{Tab}")
sleep(1)
send("w")
sleep(1)
Mouseclick("left")
sleep(1)
Send("{tab}")
sleep(1)
Send("w")
sleep(1)
MouseClick ("left")
sleep(1)
Send("{TaB}")
sleep(1)
Send("w")
Sleep(1)
MouseClick("left")
sleep(1)
send("{tab}")
sleep(1200)
send("z")
Sleep(1)
mouseclick("left")
EndFunc

Func Combo5()
Send("{Tab}")
sleep(1)
send("w")
sleep(1)
Mouseclick("left")
sleep(1)
Send("{tab}")
sleep(1)
Send("w")
sleep(1)
MouseClick ("left")
sleep(1)
Send("{TaB}")
sleep(1)
Send("w")
Sleep(1)
MouseClick("left")
Sleep(1)
send("{tab}")
Sleep(1)
send("w")
Sleep(1)
MouseClick("left")
Sleep(1)
Send("{Tab}")
sleep(1200)
send("z")
Sleep(1)
mouseclick("left")
EndFunc

Share this post


Link to post
Share on other sites



Why do you need to select the function in the gui if you also need to press a specific hotkey to start a function, or do you want the same hotkey to start a function depending on what you have selected in the gui?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Why do you need to select the function in the gui if you also need to press a specific hotkey to start a function, or do you want the same hotkey to start a function depending on what you have selected in the gui?

Yes exactly like that, My hotkeys to use are verry limited, F5 is bound to nothing so i thought that was the best way to do it.

Edited by Holepater

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You can do something like this

Edit: Added a sleep in your loop so you dont burn your cpu more than needed

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>


Global $Combo2

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 433, 280, 192, 124)

;;;;;;;;;;;;;;;;;;;;;;;
$Label2 = GUICtrlCreateLabel("Combo", 296, 56, 55, 17)
$Combo2 = GUICtrlCreateCombo("", 264, 88, 121, 25)
GUICtrlSetData($Combo2, "Combo3|Combo4|Combo5", "Combo3")
;//////////////;

#EndRegion ### END Koda GUI section ###



GUISetState(@SW_SHOW)

;hotkeys

While 1
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
    hotkeyset("{F5}", GUICtrlRead($Combo2))
WEnd


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Func
Func Combo3 ()
Send("{Tab}")
sleep(1)
send("w")
sleep(1)
Mouseclick("left")
sleep(1)
Send("{tab}")
sleep(1)
Send("w")
sleep(1)
MouseClick ("left")
sleep(1)
Send("{TaB}")
sleep(1200)
send("z")
Sleep(1)
mouseclick("left")
EndFunc

Func Combo4()
Send("{Tab}")
sleep(1)
send("w")
sleep(1)
Mouseclick("left")
sleep(1)
Send("{tab}")
sleep(1)
Send("w")
sleep(1)
MouseClick ("left")
sleep(1)
Send("{TaB}")
sleep(1)
Send("w")
Sleep(1)
MouseClick("left")
sleep(1)
send("{tab}")
sleep(1200)
send("z")
Sleep(1)
mouseclick("left")
EndFunc

Func Combo5()
Send("{Tab}")
sleep(1)
send("w")
sleep(1)
Mouseclick("left")
sleep(1)
Send("{tab}")
sleep(1)
Send("w")
sleep(1)
MouseClick ("left")
sleep(1)
Send("{TaB}")
sleep(1)
Send("w")
Sleep(1)
MouseClick("left")
Sleep(1)
send("{tab}")
Sleep(1)
send("w")
Sleep(1)
MouseClick("left")
Sleep(1)
Send("{Tab}")
sleep(1200)
send("z")
Sleep(1)
mouseclick("left")
EndFunc
Edited by Geir1983

Share this post


Link to post
Share on other sites

Thank you for the solution, now i can finish my project and i've learned how to deal with that in the future :)

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