Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use keyboard input to be an input to a googlechrome browser simultaneosly 2

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
0
16
PH
Hi everyone.. is there a way or code that what ever input is put in my application is also sent to my open google chrome browser? Thanks in advance...
 
Hello Mandy,

I don't see how this could work. Your VFP program would have to trap every key that it receives, regardless of whether it was running a form, a report, or anything else at the time. And even if those keystrokes could be sent to the browser, how would it know what to do with them?

That said, the following code might give you a start:

Code:
* Do this line once only, at the start of your program
DECLARE Sleep IN WIN32API INTEGER iPeriod

* Do this line once only, provided owsh stays in scope
oWSH = CREATEOBJECT("wscript.shell")

* Do this at the point that you want to send keys to the browser:
*( assume that Chrome is already loaded and ready to receive the keys)

owsh.AppActivate("chrome")
Sleep(500)   && short pause
lcKeys = "[URL unfurl="true"]www.tek-tips.com"[/URL]  && these are the keystrokes you want to send
owsh.Sendkeys(lcKeys)

The above code should send the specified data to the browser, but I don't know if it will achieve your aims.

Perhaps you could explain exactly what you are trying to achieve. What is your ultimate goal in sending keystrokes to Chrome? There might be some alternative way of achieving it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The usual need to automate a browser is to fill in a form and submit it. You don't. You use an API or you analyze once what is the html form and its inputs and how they are named and what's the submit action, either post or get, then you can do the same as the html form with a http request with the same action and content-type as the form uses.

If you want to do that, there are surely a lot of examples here alraddy, if not, then I don't know what you actually want to achieve. If you want to let users use a website within your application you can also embed the webbrowser control (ActiveX) on a VFP form to enable that. So filling in the HTML form becomes part of your application and isn't happening in a separate browser window.

Chriss
 
hi chriss and mike... my app gets an id number, i want the same id number to be sent/inputed in the chrome browser... thanks
 
Mandy,

Presumably you know how the ID number gets into your application. Once you know what the ID number is, you could the code I posted above to send it to Chrome. Just place the ID in lcKeys.

But that's different to what you originally asked: how to send "what ever input is put in my application" to Chrome.

Also, while my code will send the ID to Chrome, it has no way of knowing if Chrome is ready to receive it.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I bet you want the ID to go somewhere in chrome, inside a webpage already open. There is no sending data to Chrome or any browser in general, that would sort out where it needs to go to. Sending keys to chrome like Mikes code does, will add the send keys to whatever is the currently focused input control. If a website hasn't a focused input control at all, those sent keys are simply lost, unprocessed, going to NUL.
If you have no website open, so Chrome just shows about:blank, nothing happens. The keys you send might go into the address bar.

Anyway, all this means you don't have any real and necessary control what happens with the keys sent to a browser.

What you want surely is more specific. There is the whole topic of application automation, that also covers browser automation. And as I pointed out there is the webbrowser control. You get it from inserting an Olecontrol to your form and then in the dialog asking which ole control to add, pick the Microsoft Webbrowser Control. Then you can for example use a method navigate2(url).

Automating anything with sending key strokes is inferior to more direct ways of getting the data where you want it to go. Just sending keys to a browser the user could click anywhere else while the keys are processed. In the bigger picture automation of applicationy by playing back keyboard and mouse moves and clicks is depending on screen resolution, tiing and can easily fail., it's not a route you should go after.

Chriss
 
hi Mike.. I followed your instruction, but i always get "Object OWSH is not found..." when i put the idnumber in the lckeys...
 
Well, mike said (in the commtn of his code: provided owsh stays in scope)

Do you know what variable scope is? If not, why don't you ask what that comment means?

If you do this in the command window, doing oWSH = CREATEOBJECT("wscript.shell") creates a variable oWSH you can use in further commands you enter, as long as you don't RELEASE oWSH or do oWSH=.NULL.

In a prg that scope depends on using LOCAL oWSH or PUBLIC oWSH or just the assigment, creating a private variable.

If you want to use it in some method, it won't wurt to do oWSH = CREATEOBJECT("wscript.shell") again, before using it, not depending on a gloablly scope oWSH.

Chriss
 
Hi chriss... i got it.. Thanks to you and Mike so much... it worked like magic,... this is so enjoyable.... Thanks again...
 
Just be warned about mixed results.

If I do Mikes code while Chrome iss up and his source code is selected (beause I copied it into a VFP edit window of a program) nothing happens in Chrome. The text cursor/focus is in a readonly HTML textarea, so sent keys are ignored)

If I do Mikes code while Chrome is up and I put the text cursor into the post or "reply to this Thread" textarea, the text is addedd to the area (but sometimes not, when activating chrome takes more than 500ms, and that is sometimes the case)

If I close Chrome and do Mikes code, the sent keys end up in the program edit window instead of Chrome.

So you see my warnings are not just academic, the results of this kind of automation depend on timing, here. If you really want to go down the path of automating something that way, there is something better than what you can do with VFP: Autoit:
But even with AutoIt to automate Chrome they recommend using other things, a) Selenium and b) Chrome Webdriver. Which in essence means it's not simple, too, even with the gold standard tool of UI automation.

It's much simpler to automate IE or use the Webbrowser control:
Code:
oIE = CREATEOBJECT("internetexplorer.application")
oIE.navigate("[URL unfurl="true"]https://www.tek-tips.com/login.cfm")[/URL]
oIE.visible=.t.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top