Jump to content

How to determine which button was clicked or which input box hit return.


tommytx
 Share

Recommended Posts

I have set up a Gui that loads a basic htm file named myform.htm which has two text boxes and a submit button. I am able to capture any enter or left mouse click on the form, but need to be more specific... I need to know what input box I was in when I pressed enter and which button I clicked if more than one button on the page... Is there a way to do that? Thanks....

HTM file named myform.htm

<form action=http://beachrealty.com>
Box 1 <input type=text name=tom1 id=tom1 value=""><br><br>
Box 2 <input type=text name=tom2 id=tom2 value=""><br><br>
<input type=submit name=submit value=Submit>
</form>

GUI named form.au3

#include <IE.au3>
#include <GUIConstants.au3>
#include <GuiconstantsEx.au3>
#Include <Misc.au3>
Dim $hGUI, $oIE1
$hGUI = GUICreate('Win 1', 200, 200, -1, -1)
$oIE1 = ObjCreate("Shell.Explorer.2")
$Obj1_ctrl = GUICtrlCreateObj($oIE1, 2, 2, 190, 190)
GUISetState(@SW_SHOW)
_IENavigate($oIE1, @ScriptDir & "myform.htm")
While 1
  $nMsg = GUIGetMsg()
Select
  Case $nMsg = $GUI_EVENT_CLOSE
  Exit
EndSelect
If _IsPressed("0D") Then  DoSaveHtm('Return Key')
If _IsPressed("01") Then DoSaveHtm('Left Mouse')
Sleep(100)
WEnd

Func DoSaveHtm($dog)
 $file = FileOpen("test.txt", 2)
 FileWriteLine($file, $dog & @CRLF)
 FileClose($file)
EndFunc
Edited by tommytx
Link to comment
Share on other sites

  • Moderators

tommytx,

Why not use a normal GUI rather than an embedded IE? Then it becomes really easy to determine which input was last changed: :oops:

#include <GuiconstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Global $sFocus = ""

$hGUI = GUICreate('Win 1', 200, 200, -1, -1)

$cInput_1 = GUICtrlCreateInput("", 10, 30, 180, 20)
$cInput_2 = GUICtrlCreateInput("", 10, 70, 180, 20)

$cButton = GUICtrlCreateButton("Submit", 60, 120, 80, 30)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            MsgBox(0, "Focus", "Input " & $sFocus)
    EndSwitch
WEnd

Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam)
    ; If it was an update message
    If _WinAPI_HiWord($wParam) = $EN_CHANGE Then
        ; See which input was changed
        Switch _WinAPI_LoWord($wParam)
            Case $cInput_1
                $sFocus = "1"
            Case $cInput_2
                $sFocus = "2"
        EndSwitch
    EndIf
EndFunc   ;==>_WM_COMMAND

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

Thanks for that very nice response Melba, but I may not have made myself clear in my explanation. I have no control over the form page... Specifically its a Capture page and my script above is doing wonderful to tell me when enter key was hit and when a mouse click occurs. what I want to do is call a sub called DoImage() to take a snapshot of the page once the capture is typed so I have an image of the capture coded typed... so what I am doing is on enter key or mouse click.. I make a snapshot then continue with enter or mouseclick command.. That works fine.. its just that if someone clicks in the capture box so they give it focus to type in the box it lights off my capture image..(which I don't need that one) if someone clicks on the scroll bar to drag the capture box into view it lights off my capture image..(which i don't need that one) so my hope was to be able to detect where the click was at the time... in the beginnign of the box for focus or the scroll bar for moving etc... so If I could detect the Submit was clicked.. DoImage() is fine... or enter once the capture box is filled is OK... but not any other click... so bottom line.. I can imbed the page but I have Zero control over someone elses page... hope that clarifies what I am trying to accomplish... so that you may better visualize my problem and may be able to offer any other suggestion... as I dont' see how I can do what you suggest.... Thank you so very much for your efforts... This is probably so run on it makes absolutely no sense at all.... heee...hee.

I suppose I could use some sort of X,Y reporting... but the page is not normally active when this is being monitored... but I am willing to try anything..

Edited by tommytx
Link to comment
Share on other sites

Now that I think about it, maybe its possible to use X,Y coordinates somehow.. for example the only two clicks I want to honor is

1. Enter action when the cursor is in the input text box.. which is at a specific coordinate.

2. Mouse click but only when it is ontop of the submit button which also has a coordinate.

I will play with trying to see if I can qurey the positoion of the cursor when the click occurs and if not one of the above coordinates just ignore it... I will work on that.. if anyone can offer assistance in spotting hte cursor positon when clicked, pleas chime in...

Something like:

If _IsPressed("0D") Then DoSaveHtm('Return Key')

(But ignore if the coordinates of the cursor is not x,y etc)

If _IsPressed("01") Then DoSaveHtm('Left Mouse')

(But ignore if the coordinates of the cursor is not x,y etc)

anyway I will go work on this... to see if I can find a way to detect the cursor at those two instances... seems like there is a command for that.... hope...hope...

Link to comment
Share on other sites

  • Moderators

tommytx,

what I want to do is call a sub called DoImage() to take a snapshot of the page once the capture is typed so I have an image of the capture coded typed

To me that sounds as if you are trying to obtain images of CAPTCHA originals and decodes once the user has entered the plaintext. Is that indeed the case? :oops:

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

Sorta but not for any illegitimate purpose, what I am doing is studying the system so that I am more efficient at it.. for example I have to be able to type the capture pretty quick before someone else beats me... so I am looking for ways to get faster and more accurate... For example thru study of past fails and a review of the image and what I typed as the answer I can look back and see why I missed and it just helps me have a better eye for it and of course practice makes perfect... You see its competition and the first one to get the capture right gets the prize... not a real big deal but seems to be a lot of fun to beat out the others..... for example i have found that on occasion they will not accept the enter key.. so now I use the submit key on all entries...

Edited by tommytx
Link to comment
Share on other sites

  • Moderators

tommytx,

I see. And do all your other threads deal with the same script? :oops:

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

NO most are unrelated... I am playing with several projects... none are of very much.. as I am just getting back to learning Autoit again.. and build just about anything I can think of...

Usually none of them ever get done... I just start them and then stray to another interesting project...

You see as I am retired and only do things for fun...... anything i do for anyone anymor is for free...

Link to comment
Share on other sites

  • Moderators

tommytx,

Anything to do with reading CAPTCHAs is not permitted here. Your other threads will remain open - unless I find as I go through them that I think they have anything to do with CAPTCHAs as well (you did day "most" were unrelated). If you ever mention anything to do with CAPTCHAs in any form again you will get a holiday from the forum. I hope I am being sufficiently clear. :oops:

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

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...