Jump to content
Sign in to follow this  
bazinga

Array, ComboBox and _IsPressed

Recommended Posts

bazinga

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

Share this post


Link to post
Share on other sites
Melba23

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

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
FireFox

The _IsPressed function takes hexadecimal numbers, 58 <> 0x58. Either turn your integers into strings or put directly the hexadecimal numbers in your array.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
bazinga

oh yea, its working :) thanks alot Melba23!

well, one more question: why do i have to use "user32.dll" when using _IsPressed in a loop? any disadvantages if i dont do? i ask, because i cant see a difference :S

Share this post


Link to post
Share on other sites
Melba23

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

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
bazinga

aah ok. thank you very much :)

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  

×