kylomas Posted February 14, 2011 Share Posted February 14, 2011 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. expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2011 Moderators Share Posted February 14, 2011 kylomas,Use a dummy control and set "ENTER" as an accelerator key like this: expandcollapse popup#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_DummyAll clear? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted February 14, 2011 Author Share Posted February 14, 2011 (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 February 14, 2011 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 Link to comment Share on other sites More sharing options...
kylomas Posted February 14, 2011 Author Share Posted February 14, 2011 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2011 Moderators Share Posted February 14, 2011 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kylomas Posted February 14, 2011 Author Share Posted February 14, 2011 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 14, 2011 Moderators Share Posted February 14, 2011 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now