moving mouse pointer and entering text

Just starting out? Need help? Post your questions and find answers here.
User avatar
sirrab
Enthusiast
Enthusiast
Posts: 106
Joined: Thu Dec 07, 2006 8:52 am
Location: New Zealand

moving mouse pointer and entering text

Post by sirrab »

HI :)

question.

Is it possible to move the mouse pointer and enter text in a webgadget ?

Thanks :)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: moving mouse pointer and entering text

Post by netmaestro »

Your question as stated is too vague. Exactly what are you trying to accomplish?
BERESHEIT
User avatar
sirrab
Enthusiast
Enthusiast
Posts: 106
Joined: Thu Dec 07, 2006 8:52 am
Location: New Zealand

Re: moving mouse pointer and entering text

Post by sirrab »

HI,

I want to fill in a form on a website and then click to login.

Thanks :)
User avatar
Shardik
Addict
Addict
Posts: 2069
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: moving mouse pointer and entering text

Post by Shardik »

This code example should get you going. It demonstrates how to fill in text into an input field and how to click onto a login button using a simple html form in a WebGadget for demonstration purposes (tested with PB 5.31 x86 on Windows XP SP3 and PB 5.31 x64 and x86 on Windows 8.1):

Code: Select all

EnableExplicit

Procedure.I WriteTextIntoHTMLElement(WebGadgetID.I, ElementName.S, Text.S)
  Protected BSTRText.S = Space(128)
  Protected Document.IHTMLDocument3
  Protected Dispatch.iDispatch
  Protected Element.IHTMLElement
  Protected InputElement.IHTMLInputElement
  Protected Result.I
  Protected Value.I
  Protected WebBrowser.IWebBrowser2 = GetWindowLongPtr_(GadgetID(WebGadgetID), #GWL_USERDATA)

  If WebBrowser\get_Document(@Dispatch) <> #S_OK
    Dispatch\Release() 
    ProcedureReturn #False
  EndIf

  If Dispatch\QueryInterface(?IID_IHTMLDocument3, @Document) <> #S_OK
    Document\Release()
    Dispatch\Release()
    ProcedureReturn #False
  EndIf

  If Document\getElementById(ElementName, @Element) <> #S_OK Or Element = 0
    Document\Release()
    Dispatch\Release()
    ProcedureReturn #False
  EndIf

  If Element\QueryInterface(?IID_IHTMLInputElement, @InputElement) <> #S_OK
    Element\Release()
    Document\Release()
    Dispatch\Release()
    ProcedureReturn #False
  EndIf

  Result = InputElement\put_value(Text)
 
  InputElement\Release()   
  Element\Release()   
  Document\Release()   
  Dispatch\Release()   
   
  If Result = #S_OK
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf 
EndProcedure

Procedure NavigationCallback(GadgetID.I, URL.S)
  If FindString(URL, "LoginButtonClick")
    MessageRequester("Info", "Login button was clicked!")
  EndIf
EndProcedure

Define HTML.S
Define SelectedFilename.S

HTML + "<html><body><form name='TestForm' action='' method='get'>" + #CR$
HTML + "Your login name: <input name=" + #DQUOTE$ + "Name" + #DQUOTE$
HTML + " type=" + #DQUOTE$ + "text" + #DQUOTE$
HTML + " size=15 maxlength=15>" + #CR$
HTML + "<br>" + #CR$
HTML + "<br>" + #CR$
HTML + "<center>" + #CR$
HTML + "<input type='button' value='Login' onClick='window.location=" + #DQUOTE$ +"LoginButtonClick" + #DQUOTE$ + "'>" + #CR$
HTML + "</center>" + #CR$
HTML + "</form>" + #CR$
HTML + "</body>" + #CR$
HTML + "</html>" + #CR$

OpenWindow(0, 0, 0, 280, 140, "Login form demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
WebGadget(0, 5, 5, WindowWidth(0) - 10, WindowHeight(0) - 40, "")
ButtonGadget(1, 20, WindowHeight(0) - 25, 100, 20, "Fill in login name")
ButtonGadget(2, 140, WindowHeight(0) - 25, 120, 20, "Click onto login button")

SetGadgetItemText(0, #PB_Web_HtmlCode, HTML)
SetGadgetAttribute(0, #PB_Web_NavigationCallback, @NavigationCallback())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      End
    Case #PB_Event_Gadget
      Select EventGadget()
        Case  1
          WriteTextIntoHTMLElement(0, "Name", "JohnSmith")
        Case 2
          SetGadgetText(0, "javascript:document.TestForm.LoginButtonClick.submit();")
      EndSelect
  EndSelect
ForEver

End

DataSection
  IID_IHTMLDocument3:
    Data.L $3050F485
    Data.W $98B5, $11CF
    Data.B $BB, $82, $00, $AA, $00, $BD, $CE, $0B

  IID_IHTMLInputElement:
    Data.L $3050F5D2
    Data.W $98B5, $11CF
    Data.B $BB, $82, $00, $AA, $00, $BD, $CE, $0B
EndDataSection
User avatar
sirrab
Enthusiast
Enthusiast
Posts: 106
Joined: Thu Dec 07, 2006 8:52 am
Location: New Zealand

Re: moving mouse pointer and entering text

Post by sirrab »

Thanks Shardik !

will have a play :)
Post Reply