Sign in to follow this  
Followers 0
kylomas

GuiCtrlCreatInput onevent not firing

7 posts in this topic

Hi All,

I am trying to detect when the enter key is depressed and $f10inp is blank. The event fires when I backspace to create a blank field, but not when the enter key is depressed and no data entered.

#AutoIt3Wrapper_UseX64=N
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <ProgressConstants.au3>
#include <ListboxConstants.au3>
#include <EditConstants.au3>

Opt('mustdeclarevars', 1)
Opt('guioneventmode', 1)

Global $title = "File Renaming Gizmo"
Global $com,$hdr1,$f10lbl,$f10inp,$p1,$flst,$fllstl,$r10lbl,$r10inp,$rlstl,$rlst,$f10err,$r10err

            GUISetFont(8.5, 600, 1, 'Courier New')
$com    =   GUICreate("File Renamer", @DesktopWidth - 50, @DesktopHeight - 100)
$hdr1   =   GUICtrlCreateLabel($title, 50, 20, @DesktopWidth - 150, 40, $ss_center+$ss_sunken)
            GUICtrlSetFont(-1, 20, 800, 1, "Comic Sans MS")
            GUICtrlSetColor(-1, 0x800000)
$f10lbl =   GUICtrlCreateLabel('Enter file pattern (* and ? allowed)', 50, 75, 350)
            guictrlsetfont($f10lbl,8.5,600,'','Times New Roman')
$f10inp =   GUICtrlCreateinput('', 50, 95, 400, 20, -1)
            guictrlsetonevent($f10inp,"file010")
$f10err =   guictrlcreatelabel('',50,125,400,20)
$fllstl =   guictrlcreatelabel('Matching Files',50,155,400,20)
$flst   =   GUICtrlCreateEdit('', 50, 170, 400, 450, $ES_AUTOVSCROLL + $WS_VSCROLL + $ws_hscroll)
            GUICtrlSetLimit($flst, 1000000) ; 1 million byte edit char limit
$r10lbl =   GUICtrlCreateLabel('Enter Rename Pattern (include wild cards * and ?)', 525, 75, 350)
            guictrlsetfont($r10lbl,8.5,600,'','Times New Roman')
$r10inp =   GUICtrlCreateinput('', 525, 95, 400, 20, -1)
$r10err =   guictrlcreatelabel('',525,125,400,20)
$rlstl  =   guictrlcreatelabel('Files Will Be Renamed As Follows',525,155,400,20)
$rlst   =   GUICtrlCreateEdit('', 525, 170, 400, 450, $ES_AUTOVSCROLL + $WS_VSCROLL + $ws_hscroll)
            GUICtrlSetLimit($rlst, 1000000) ; 1 million byte edit char limit
$p1     =   GUICtrlCreateProgress(50, 660, @DesktopWidth - 150, 5, $PBS_SMOOTH)
            GUISetState()
            GUISetOnEvent($gui_event_close, '_fini')

While 1
    Sleep(100)
WEnd

func file010()

    local $flin = guictrlread($f10inp),$file,$flattr
    c($flin)
    guictrlsetdata($f10err,'')
    guictrlsetdata($flst,'')
    if $flin = ' ' then
        fileopendialog('Select a File to use as a Pattern','c:\','All(*.*)')
        if @error then c(@error)
    EndIf
    if stringlen($flin) < 1 then
        fileopendialog('Select a File to use as a Pattern','c:\','All(*.*)')
        if @error then c(@error)
    EndIf




    local $files = FileFindFirstFile($flin)

    If $files = -1 Then
        guictrlsetdata($f10err,"Error - No files/directories matched the search pattern")
        return
    EndIf

    While 1
        $file = FileFindNextFile($files)
        If @error Then ExitLoop
        if @extended = 1 then ContinueLoop
        consolewrite($flattr & @lf)
        GUICtrlSetData($flst, $file & @crlf,1)
    wend

endfunc

Func _fini()
    Exit
EndFunc   ;==>_fini

func c($str)
    consolewrite('$DEBUG:>> ' & $str & @lf)
endfunc

Thanks,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites



kylomas,

Use a dummy control and set "ENTER" as an accelerator key like this: ;)

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Opt('GUIOnEventMode', 1)

$hGUI = GUICreate("Test", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit")
$hInput = GUICtrlCreateInput("", 10, 10, 100, 20)
$hButton = GUICtrlCreateButton("clear text", 120, 10)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetOnEvent(-1, "On_Clear")
$hDummy = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "On_Dummy")

GUISetState(@SW_SHOW)

; Set accelerator for Enter to action the Dummy code
Dim $aAccelKeys[1][2] = [["{ENTER}", $hDummy]]
GUISetAccelerators($aAccelKeys)

While 1
    Sleep(10)
WEnd

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Func On_Clear()
    GUICtrlSetData($hInput, "")
    GUICtrlSetState($hButton, $GUI_HIDE)
EndFunc   ;==>On_Clear

Func On_Dummy()
    ; Check input has focus
    If _WinAPI_GetFocus() = GUICtrlGetHandle($hInput) Then
        $sText = GUICtrlRead($hInput)
        MsgBox(0, "test", "You typed in " & $sText)
        GUICtrlSetState($hButton, $GUI_SHOW)
    EndIf
EndFunc   ;==>On_Dummy

All clear? :)

M23


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

#3 ·  Posted (edited)

M23,

The "how" of it is clear, but not the "why" of it (I just do NOT understand how Windows works, apparently!).

kylomas

Edit: light is comming on!

Dummy control is used because accelerator table is associated with a control.

Accelerator key = hot key

Is this close?

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

M23,

This is what I don't get.

Normal sequence of events:

The dialog is displayed and my input field has focus (is this a bad assumption?)

User types something and hits enter

Function guictrlread gets whatever the user has typed into the input box.

So...

What is the difference if the user has hit enter without typing anything in the input box?

Also,

A little Googling leads me to believe that accelerator keys are the same as hotkeys. Autoit has a hotkey keyword, however. So what exactly is an accelerator key from AuoIT's perspective?

Thanks,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

kylomas,

Questions, questions..... :)

Accelerator keys are like HotKeys except that they only work within their GUI when it is active - unlike HotKeys which work all the time, even when other GUIs are active. I like using Accelerator keys for this reason - however, because they must be linked to a control, they are less powerful than HotKeys. Take a look at the Interrupting a running function tutorial in the Wiki and you will see the difference in how the 2 types can be used.

As I have just explained, an Accelerator key needs a control to action, so in this case I used a Dummy. Of course, you can link them to existing controls as well as the Help file example shows.

As to why ENTER does not work if there is nothing in the input, I belive that you need an EN_CHANGE message from the input to activate the normal ENTER response - as nothing has changed in the input if nothing has been entered, the ENTER key is not activated and you do not get the normal response. I read something in more detail somewhere on the forum - I will try and dig it up later.

All clear? ;)

M23


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

M23,

Yes, I'll stop with the questions now.

Thanks,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

kylomas,

Always happy to answer questions if I can. :)

M23


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

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