Jump to content
Sign in to follow this  
BitByteBit

Select all text in inputbox, listen for Enter

Recommended Posts

BitByteBit

I have a gui with a button and an input box.

If the input box is clicked then select all text, if enter is press whilst it has focus then run a function.

I know what commands to use, but I'm puzzled as to how I work them into my Switch since this relys on GUIGetMsg which I need to listen for the buttons.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=MTSE.exe
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <String.au3>
Opt("GUIResizeMode",802)
Opt("TrayIconDebug",1)
HotKeySet("!r","Resize")
$Big = False
Global $Proper
_IEErrorHandlerRegister ()
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("MTSE 2", 299, 56, 10,10)
;GUICreate(w,h,l,t
GUISetBkColor(0x000000)
$Search = GUICtrlCreateInput("Search", 1, 0, 297, 30, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
GUICtrlSetFont(-1, 12, 400, 0, "Palatino Linotype")
$Google = GUICtrlCreateButton("Google", 0, 30, 75, 25, $WS_GROUP)
GUICtrlSetBkColor (-1, 0x000080)
GUICtrlSetFont(-1, 12, 400, 4, "Palatino Linotype")
GUICtrlSetColor(-1, 0xFFFFFF)
$Back = GUICtrlCreateButton("Back", 308, 0, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 4, "Palatino Linotype")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000080)
$Forward = GUICtrlCreateButton("Forward", 388, 0, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 4, "Palatino Linotype")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000080)
$Refresh = GUICtrlCreateButton("Refresh", 308, 32, 155, 25, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 4, "Palatino Linotype")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000080)
$Resize = GUICtrlCreateButton("Resize", 470, 0, 123, 25, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 4, "Palatino Linotype")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000080)
$IE = _IECreateEmbedded ()
$GUIActiveX = GUICtrlCreateObj($IE, 10, 70, 985 , 600)
_IENavigate($IE,'www.google.co.uk')
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;Dim $Window = $IE.document.parentWindow
GUICtrlSetState($Search, $GUI_FOCUS)
Send("^a")
While 1
    $nMsg = GUIGetMsg()
    ;$Msg= GUIGetMsg ($GUI_EVENT_PRIMARYDOWN)
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    Case $Google
        Google()
    Case $Search
        Send("!a")
    EndSwitch
WEnd




Func Back()
_IEAction ($IE, "back")
EndFunc

Func Forward()
_IEAction ($IE, "forward")
EndFunc

Func Refresh()
$URL = _IEPropertyGet($IE, "locationurl")
_IENavigate($ie,$url)
EndFunc

Func Google()
Proper()
If $big = false then Resize()
_IENavigate($IE,"http://www.google.co.uk/search?hl=en&source=hp&q=" & $Proper & "&btnG=Google+Search&meta=&aq=f&oq=",1)
EndFunc

Func Resize()
$Pos = WinGetPos("MTSE 2")
If $Big = False Then
$Big = True
WinMove("MTSE 2","",$Pos[0],$Pos[1],1010,710)

Else
$Big = False
WinMove("MTSE 2","",$Pos[0],$Pos[1],305,84)
EndIf
EndFunc

Func Proper()
$Result = GUICtrlRead($Search)
$Proper = _StringProper($Result)
GUICtrlSetData($Search,$Proper)
EndFunc

Share this post


Link to post
Share on other sites
Melba23

BitByteBit,

A few lines to add to your code just before and within your While...WEnd loop:

$dll = DllOpen("user32.dll")
$Search_Handle = GUICtrlGetHandle($Search)

While 1
    $nMsg = GUIGetMsg()
    ;$Msg= GUIGetMsg ($GUI_EVENT_PRIMARYDOWN)
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Google
            Google()
        Case $GUI_EVENT_PRIMARYDOWN
            $aCurInfo = GUIGetCursorInfo()
            If $aCurInfo[4] = $Search Then
                Sleep(100)
                Send("{HOME}{SHIFTDOWN}{END}{SHIFTUP}")
            EndIf
    EndSwitch

If _IsPressed("0D", $dll) And _WinAPI_GetFocus() = $Search_Handle Then
    ConsoleWrite("I can run a  function!" & @CRLF)
    While _IsPressed("0D", $dll)
        Sleep(10) ; Important so as not to use 100% CPU!
    WEnd
EndIf

WEnd

It seems Input controls do not send messages, so we have to take a roundabout way of looking for a click and then seeing if the mouse if over the Input. As to the hitting the Enter key, you can see how it checks if the Input has focus before doing anything. As we are polling _IsPressed in a loop, it is good practice to open the DLL beforehand - but you then need to close the DLL once you no longer need to check for the keypress.

Despite its less than elegant form, I hope this code helps. :)

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
BitByteBit

Most excellent dude, thanks for taking the time to help me with this one, again!

Is the while necessary? I'm guessing it's to stop the function being run over and over whilst enter is pressed?

Share this post


Link to post
Share on other sites
Melba23

BitByteBit,

Good guess! :) Try taking it out and see what happens! ;)

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  

×