Jump to content
Sign in to follow this  
BartDog

Using a ComboBox selection as the Hotkey

Recommended Posts

OK I use a simple script from a GUI (similar to the example below) to send strings of letters to whatever I am working on.  I use this as a shortcut to send whatever things I happen to need to type multiple times a day like my name.  I have this HotKeySet to my F6 key and it works great. 

What I want to do is use a ComboBox to indicate what the hotkey is set to.  So I could have a list of keys rather then it set to just F6. 

I can’t seem to find anything in the help files under ComboBox or HotKeySet or on the Forums.  Am I blind? Or does anyone have somewhere else I can look or the answer to my dilemma?

This example is what I am trying to get working.

 

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

HotKeySet("$HotKey", "OutPut")

$Form1 = GUICreate("Test", 288, 215, 519, 347)
$HotKey = GUICtrlCreateCombo(" set hotkey ", 128, 64, 121, 25)
GUICtrlSetData(-1, "F2|F3|F4|F5|F6")  ;have tried {F2}|{F3}...
GUISetState()

$Label1 = GUICtrlCreateLabel("UserName", 16, 64, 36, 17)
GUISetState(@SW_SHOW)

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

Func OutPut()
    Send("The Text or Name Here")
    Send("{ENTER}")
EndFunc   ;==>OutPut



My heart is not set on a combo box if anyone has another idea.  It would be cool to have a button to push to map the next key hit but that seems overly complicated for what I need.

 

Thanks In advance for any advice!

 

Share this post


Link to post
Share on other sites

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

Global $Output = 0

HotKeySet("$HotKey", ""&$Output )

Example()

Func Example()

    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a checkbox control.
    Local $idCheckbox = GUICtrlCreateCheckbox("Standard Checkbox", 10, 10, 185, 25)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop
            
            Case $idCheckbox
                If _IsChecked($idCheckbox) Then
                    $output = "Output1"
                EndIf
            Case $idCheckbox2
                If _IsChecked($idCheckbox2) Then
                    $output = "Output2"
                EndIf

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Func OutPut1()
    Send("The Text or Name Here")
    Send("{ENTER}")
EndFunc   ;==>OutPut
Func OutPut2()
    Send("allo")
    Send("{ENTER}")
EndFunc   ;==>OutPut

This will help your logic

you have to particulary check this out :

HotKeySet("$HotKey", ""&$Output )

&$Output

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked
Case $idCheckbox
                If _IsChecked($idCheckbox) Then
                    $output = "Output1"
                EndIf
            Case $idCheckbox2
                If _IsChecked($idCheckbox2) Then
                    $output = "Output2"
                EndIf
Func OutPut1()
    Send("The Text or Name Here")
    Send("{ENTER}")
EndFunc   ;==>OutPut

For the buttom that you whould like to have if you use my logic it keep it simple as that :

Local $iButton1 = GUICtrlCreateButton("Swap", *, *, *, *)

Replace * by your location

Case $iButton1

       $output = $Output + 1

And dont forget to make your value going back with somthing like that ....

If $output = Output5 then 
$Output = Output1

Or if you're hitting button you wont go back as a while. to call precedent functions

Hope i am clear xD

This exemple missing a second GUI checkbox but the logical way is here you have just to complete ;) come here to say us if that is ok for you

thx and bye.

The only thing i am not sure is maybe you have to call the Global $Output in a function to be sure he get the correct value but i am realy not sure. If you can try and come back to say us ;)

Cara

Edited by caramen

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

sorry I posted some code for hotkey combo boxes but I see it has too many dependencies to other include files I no longer have.  The basic scheme was one combo box for modifier keys and a second combo box for the main hotkey.  The user would select modifiers such as ControlShift and a main hotkey such as F5 or NumPadAdd and when pressing OK button the two would be put together in a hotkey string usinng a Select.  For example if the user selected modifiers ControlShift and hotkey {NumPadAdd} the result would be "^+{NumPadAdd}"

 

Edit:  to give an idea, here are the strings I used for the combo box data

 

Local $combomainkeys = "c|e|r|v|x|{Esc}|{BS}|{F1}|{F2}|{F3}|{F4}|{F5}|{F6}|{F7}|{F8}|{F9}|{F10}|{F11}|"
    $combomainkeys &= "{Up}|{Down}|{Left}|{Right}|{Home}|{End}|{Pause}|{PgUp}|{PgDn}|{NumPadAdd}|{NumPadSub}|"
    $combomainkeys &= "{NumPadMult}|{NumPadDiv}|{SPACE}"
    Local $combomodkeys = "Alt|Control|Shift|Winkey|ControlAlt|ControlShift|ControlWinkey|ShiftAlt|ShiftWinkey"
Here is the function with the Select that put the two pieces together

Func _build_hotkey($mod, $main)
    Local $modkey = ""
    Select
        Case $mod = "Alt"
            $modkey = "!"
        Case $mod = "Control"
            $modkey = "^"
        Case $mod = "Shift"
            $modkey = "+"
        Case $mod = "WinKey"
            $modkey = "#"
        Case $mod = "ControlAlt"
            $modkey = "^!"
        Case $mod = "ControlShift"
            $modkey = "^+"
        Case $mod = "ControlWinkey"
            $modkey = "^#"
        Case $mod = "ShiftAlt"
            $modkey = "+!"
        Case $mod = "ShiftWinkey"
            $modkey = "+#"
        Case Else
            $modkey = ""
    EndSelect
    If ($main <> "c") And ($main <> "e") And ($main <> "r") And ($main <> "v") And ($main <> "x") Then
        If Not StringInStr($main, "{") Then
            SetError(1)
            Return ""
        EndIf
    EndIf
    Return $modkey & $main
EndFunc   ;==>_build_hotkey
Edited by MilesAhead

Share this post


Link to post
Share on other sites

what is the purpose of

$combomainkeys &=

"&" =?

can you explain me ?


My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

oh ok!


My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thank you Caramen and MilesAhead.  I will be looking into your suggestions more this weekend.  

Also I found these 2 libraries by Yashied that look like they will work awesomely if only I can figure them out:

HotKeyInput UDF Library v1.3

HotKey UDF Library v1.8

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  

×
×
  • Create New...