Recent

Author Topic: Send char to active webbrowser page  (Read 3712 times)

lazzaro2023

  • New Member
  • *
  • Posts: 36
Send char to active webbrowser page
« on: February 09, 2023, 06:06:51 pm »
I have the following problem:
I have a memo with n lines.
I need to copy into the clipboard the memo lines individually from the last one to the first one and send them to the web browser's active page keyboard buffer.
I don't know how to intercept the keyboard buffer to send the copied memo lines to the clipboard.
I hope I have been clear and cause the readers of this post to have bad thoughts about my intentions.
Can someone please help me.


Bogen85

  • Hero Member
  • *****
  • Posts: 703
Re: Send char to active webbrowser page
« Reply #1 on: February 09, 2023, 06:45:18 pm »
I hope I have been clear and cause the readers of this post to have bad thoughts about my intentions.

And not cause the readers...

Since so much today is remote web page (app, whatever...) centric, I don't see why trying to control one's own browser's access to a web page as by default being nefarious.

balazsszekely

  • Guest
Re: Send char to active webbrowser page
« Reply #2 on: February 09, 2023, 07:16:10 pm »
The question is how do you plan to do it?
  1. Open a browser from your application
  2. Go to a specific page
  3. Find a specific html element
  4. Focus the html element
  5. Send memo text to the html element

If yes then what is the exact page and html element? It's almost impossible to help without knowing the page/element. The hardest part in the list is point 3 and 4.
Or perhaps do you have something else in mind?

lazzaro2023

  • New Member
  • *
  • Posts: 36
Re: Send char to active webbrowser page
« Reply #3 on: February 09, 2023, 07:51:09 pm »
The question is how do you plan to do it?
  1. Open a browser from your application
  2. Go to a specific page
  3. Find a specific html element
  4. Focus the html element
  5. Send memo text to the html element

If yes then what is the exact page and html element? It's almost impossible to help without knowing the page/element. The hardest part in the list is point 3 and 4.
Or perhaps do you have something else in mind?

Thank you! That's exactly what I intend to do and I am also struggling with points 3 and 4.
The HTML page in question consists of an HTML form with input fields and I am using this HTML page example as a reference: https://www.w3schools.com/html/html_forms.asp
I need to write a program that takes the first and second line of the Tmemo and respectively sends the memory text to the HTML element "First Name" and "Last Name" in the page that I indicated to you.

balazsszekely

  • Guest
Re: Send char to active webbrowser page
« Reply #4 on: February 09, 2023, 08:55:02 pm »
Quote
Thank you! That's exactly what I intend to do and I am also struggling with points 3 and 4.
The HTML page in question consists of an HTML form with input fields and I am using this HTML page example as a reference: https://www.w3schools.com/html/html_forms.asp
I need to write a program that takes the first and second line of the Tmemo and respectively sends the memory text to the HTML element "First Name" and "Last Name" in the page that I indicated to you.
Unfortunately the browsers won't let you access the elements form outside, this is a security feature, so there is no precise way to do it, the solution will differ from page to page and even browser to browser.
After the page is opened in the default browser, you have to simulate mouse and keyboard events, something like this:
1. Open webpage
Code: Pascal  [Select][+][-]
  1. uses  LCLIntf;
  2.   //..
  3.  OpenURL(' https://www.w3schools.com/html/html_forms.asp');
  4.  
 
2. Give the browser a chance to open   
Code: Pascal  [Select][+][-]
  1.   Sleep(3000);
3.  Simulate moue and keyboard input(add lazmouseandkeyinput package to your application);
Code: Pascal  [Select][+][-]
  1. uses LCLType, MouseAndKeyInput
  2.   //...
  3.   MouseInput.Click(mbLeft, [], 500, 500);
  4.   KeyInput.Press(VK_TAB);      
  5.   //press tab until you find the element, then send the strings from memo  

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12398
  • Debugger - SynEdit - and more
    • wiki
Re: Send char to active webbrowser page
« Reply #5 on: February 09, 2023, 09:29:31 pm »
I can think of 2 approaches....

1) There is a package "KeyAndMouseInput" (or similarly named)... It allows sending keystrokes to other Windows.  More exactly IIRC to the focused Windows
- You need the Browser to have focus. (At least the MS Windows has API has functions that may allow you to set that focus).
- It simulates keystrokes. If a user hits the keyboard, or clicks/focuses another Window... It breaks.

2) https://www.selenium.dev/
But I have no idea if there is an Pascal interface to it.
There is an existing thread: https://forum.lazarus.freepascal.org/index.php?topic=50082.0

It lets you do quite some remote control of your browser.
And, if you just care about sending the result to the web server, IIRC there is a window-less browser that can load the page and do the work.


lazzaro2023

  • New Member
  • *
  • Posts: 36
Re: Send char to active webbrowser page
« Reply #6 on: February 10, 2023, 08:22:15 pm »
I can think of 2 approaches....

1) There is a package "KeyAndMouseInput" (or similarly named)... It allows sending keystrokes to other Windows.  More exactly IIRC to the focused Windows
- You need the Browser to have focus. (At least the MS Windows has API has functions that may allow you to set that focus).
- It simulates keystrokes. If a user hits the keyboard, or clicks/focuses another Window... It breaks.

2) https://www.selenium.dev/
But I have no idea if there is an Pascal interface to it.
There is an existing thread: https://forum.lazarus.freepascal.org/index.php?topic=50082.0

It lets you do quite some remote control of your browser.
And, if you just care about sending the result to the web server, IIRC there is a window-less browser that can load the page and do the work.
Thank you for the suggestion.
I brilliantly solved it by taking inspiration from point 2 that you pointed out.
Thank you, you are great!!!

lazzaro2023

  • New Member
  • *
  • Posts: 36
[SOLVED]Re: Send char to active webbrowser page
« Reply #7 on: February 11, 2023, 11:16:37 am »
Below, I attach a demo that may be of help to anyone who has encountered the same problem as I have.

 

TinyPortal © 2005-2018