Jump to content

Array, ComboBox and _IsPressed


bazinga
 Share

Go to solution Solved by Melba23,

Recommended Posts

Hello guys,

as the title says, i have a problem with array, combobox and the IsPressed function.

i try to pass the selected item to the _IsPressed function but its not working the way i do it. a little hint what to search for or a code snippet to learn from would be really nice.

thanks in advance.

Global $Array[3][2] = [ ["X", 58], ["C", 43], ["V", 56] ]

$Combo = GUICtrlCreateCombo($Array[0][0], 130, 100, 50, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
For $i = 0 To Ubound($Array) - 1
    GUICtrlSetData($Combo, $Array[$i][0], True)
Next

$Key = GUICtrlRead($Combo)


While 1
    If _IsPressed($Key) Then
        Do
            Send ("{0}")
        Until Not _IsPressed($Key)
    EndIf
WEnd
Edited by bazinga
Link to comment
Share on other sites

  • Moderators
  • Solution

bazinga,

I would do something like this:

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>
#include <Array.au3>
#include <Misc.au3>

Global $aKeys[3][2] = [ ["X", 58], ["C", 43], ["V", 56] ]
$hDLL = DllOpen("user32.dll") ; You are calling _IsPressed in a loop - so use the DLL handle
$iKeyCode = 0 ; You need to declare this

$hGUI = GUICreate("Test", 500, 500)

; Do not set a default value in the combo - then you react to the first selection
$cCombo = GUICtrlCreateCombo("", 130, 100, 50, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
For $i = 0 To Ubound($aKeys) - 1
    GUICtrlSetData($cCombo, $aKeys[$i][0])
Next

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            DllClose($hDLL)
            Exit
        Case $cCombo
            ; Combo selection changed - get index of new selection
            $iIndex = _ArraySearch($aKeys, GUICtrlRead($cCombo))
            ; Set keycode to the correct vlaue
            $iKeyCode = $aKeys[$iIndex][1]
    EndSwitch

    If _IsPressed($iKeyCode, $hDLL) Then
        Do
            Send ("0") ; No need for {}
        Until Not _IsPressed($iKeyCode, $hDLL)
    EndIf
WEnd
All clear? :)

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

bazinga,

If you do not open the DLL and use the handle in the function call you are opening and closing the DLL each time. In this case there is not a huge penalty as the user32 DLL is almost certainly open anyway - but the principle still holds that it is better to get a handle and use it if you call the function in a loop. ;)

M23

Edited by Melba23
Typo

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