B4J Question How to automate windows desktop apps

xulihang

Active Member
Licensed User
I want to automate Microsoft Word to replace text.

It needs the following steps:

  1. CTRL+H to open the search and replace dialog
  2. ALT+P to switch to replace tab
  3. ALT+N to switch to "find" and input the text
  4. ALT+I to switch to "replace" and input the text
  5. ALT+F to find a match
  6. ALT+R to replace
I tried JAWTRobot, but it does not seem to work. Is this because AWTRobot is for java programs and I should use Autoit or VBA to do this?
 

Daestrum

Well-Known Member
Licensed User
You can use JAWTRobot to interact with MS Word.

I have used it to edit files in the B4J IDE, the program it interacts with doesn't have to be a java program.
 

Daestrum

Well-Known Member
Licensed User
Or another thought you could use the POI lib and edit the word files directly.
 

xulihang

Active Member
Licensed User
You can use JAWTRobot to interact with MS Word.
I find AWTRobot partly works but combo does not work, like ctrl+h. I use the test code below. Run the B4J app and switch to Word. The dialog does not show.

B4X:
Do While True
    Log("combo")
    Sleep(1000)
    Dim awt As AWTRobot
    awt.RobotSpecialKeyCombo("ctrl_h")
Loop

use the POI lib and edit the word files directly.
I have thought about this. But it is a bit complicated and users cannot see the replacing process directly. And ultimately, I want to create a universal text replacer which works for word, excel, ppt, photoshop, indesign, etc.
 

Roycefer

Well-Known Member
Licensed User
If my recollection serves me, ctrl_h is not one of the listed combos in the comments for RobotSpecialKeyCombo. This means you will have to separately press and release the ctrl and h keys.
 

xulihang

Active Member
Licensed User
This means you will have to separately press and release the ctrl and h keys.
This works. Thanks!

B4X:
Do While True
    Sleep(1000)
    awt.RobotSpecialKeyPress("control")
    awt.RobotKeyPress("h")
    awt.RobotSpecialKeyRelease("control")
    awt.RobotKeyRelease("h")
    Log("combo")
Loop
 
Top