Jump to content

Wordpad script in progress


Bob23
 Share

Recommended Posts

Thanks kindly to genius257 for answering my earlier question.
I played with the Finder Tool to get familiar with it, and opened
a cmd window.  Then tried creating a script that uses Wordpad.
I found the path for Wordpad.exe and put that path into a batch
named WP.bat with %1.  My script opened my file using Wordpad,
then generated some text.  The last two steps I wanted were to
move cursor to top of file, which requires <Ctrl + PgUp> keys
then to open the 'Search' pop-up which requires <Ctrl + s>.

I opened my script with the Scite-Lite editor, but did not
find how to generate [Ctrl] keystroke combos.  Any suggestion?
Below is my new script in progress:

(I generally prefer (and need) to work from command line mode.)
.............................................................

#include <Constants.au3>

; Run cmd.exe
Run("cmd.exe")

WinWaitActive("[CLASS:ConsoleWindowClass]")

Sleep(1000)

; Run Wordpad
Run("wp.bat file.txt")

WinWaitActive("[CLASS:WordPadClass]")

Sleep(1000)

; Now that the Wordpad window is active type some text
Send("Line1...{ENTER}Line2...{ENTER}Line3...{ENTER}Line4{ENTER}")
Sleep(2000)

; Now go to Save by pressing Alt-F then scrolling down(x2) to 'Save'
Send("!f")
Sleep(1000)
Send("{DOWN 2}{ENTER}")
Sleep(2000)

; Now send a <Ctrl + PageUp> keystroke to move to top of file
: a prerequisite to search from top of file.

Link to comment
Share on other sites

Send("^{PGUP}")

 

 

BTW you can do all these with keyboard shortcuts

; Now go to Save by pressing Alt-F then scrolling down(x2) to 'Save'
Send("!f")
Sleep(1000)
Send("{DOWN 2}{ENTER}")
Sleep(2000)

Try this instead:

Send("!FS")

 

Edited by l3ill
Link to comment
Share on other sites

This example by-passes the cmd prompt to run WordPad.

Local $sFileName = "TestFileA.txt"

If FileExists($sFileName) Then FileDelete($sFileName)
FileWrite($sFileName, "") ; Create file

ShellExecute("write.exe", $sFileName, @ScriptDir, "open") ; Open $sFileName in WordPad.
Local $hWnd = WinWaitActive("[Class:WordPadClass]")

ControlSend($hWnd, "", "RICHEDIT50W1", "Line1...{ENTER}Line2...{ENTER}Line3...{ENTER}Line4{ENTER}")
; The "controlID" parameter can use the actual ClassnameNN value. Found from SciTE > Tools menu > Au3Info (Ctrl+F6)

ControlSend($hWnd, "", "RICHEDIT50W1", "^{PGUP}") ; Send Ctrl+PageUp (See Send function in Autoit Help - Press F1 in SciTE v.3.6.6.0)

WinWaitActive($hWnd)
; Now go to File menu by pressing Alt-F then Save by pressing Alt-S
ControlSend($hWnd, "", "RICHEDIT50W1", "!F")
Send("!S")

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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