Jump to content
jpomalley

AutoIt functions being typed as text into current text field, rather than executed as code

Recommended Posts

jpomalley

Hi folks, Im just trying to get a simple script running which will copy the text in a text field in a specific running application and close the window (which is accomplished with ctrl-shift-r then ctrl-w), then switch to firefox and paste the text into the active text edit field of the front window in firefox.

I want to execute this script with a keyboard shortcut, so I made a shortcut in windows to the script file and with "properties" of the shortcut, assigned a hotkey of F5.

The initial mouse click is to re-activate the window of the application that I am copying text out of.

The funny thing is, this script is pasting autoit functions (source code) into the app rather than executing it. For example, when I hit the F5 function key, all I notice happen is

Sleep(500)

is pasted into the application that I was using, and I don't see evidence that any of the other commands were executed (keyboard commands, firefox activation, etc.)

I searched on google for "autoit function typed rather than executed" and havent found a similar problem.

Anyone have insight? My script is below. If I delete all the Sleep(500)s, then it types "Send("^+r^w",0)" into the text edit field and doesn't appear to do anything else.

Thanks

Joe

 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
MouseClick("left")
Sleep(500)
Send("^+r^w",0)
Sleep(500)
WinActivate("Mozilla Firefox")
Sleep(500)
Send("^v",0)

 

Share this post


Link to post
Share on other sites
l3ill

Hi and Welcome...

Not sure what this is supposed to be doing but it will probably not work

Send("^+r^w",0)

{ Control + C } copies text:

Send("^c")

I would suggest testing with this.

Send("^c")
Sleep(1000)
Local $sData = ClipGet()
MsgBox(0, "Test", "Clipboard contains the text :  " & $sData)

So - Doubleclick to select word or tripleclick to select whole line and then hit your HotKey.

Once you get this working, try taking the variable and pasting it to the desired position in your other window.

Good luck !

Bill

Share this post


Link to post
Share on other sites
jchd

You can manipulate text (even being AutoIt valid syntax) as much as you wish it won't invoke the magic to actually run it, unless it is a single line which you can run using Execute(). What you can do is make that text a complete independant script which you can write to a file and execute using the same interpretor already embedded in a compiled script. Search help under "Using AutoIt > Running Sctipts > AutoIt specific command Line Switches" and don't forget to read the "Important Notes" just below.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
jpomalley

I3ill and jchd,

Thanks for your notes. With regards to what the correct keystrokes are and how to execute the script, I have those problems solved. I know what the correct keystrokes are and I am able to get the script to execute when desired.

My question is actually about something else, that is, why are the autoit functions being typed or pasted as text into the text edit window that is active, rather than being executed? (As per issue title, "AutoIt functions being typed as text into current text field, rather than executed as code")

For example, when I successfully execute my script using the method I have that works already, what the script does is, instead of waiting 500 ms, it pastes the text

Sleep(500)

into the active text window.

So what I'm trying to figure out is why the text of the autoit functions are being pasted/typed into the active window, rather than being executed as code.

Thanks if anyone can offer any help!

Joe

Edited by jpomalley

Share this post


Link to post
Share on other sites
jchd

Repeating the question ad nauseam won't help you. Reread my answer, slowly. Text is just text and an "active edit window" would have hard time turning itself by white mlagic into an AutoIt interpretor.

Would you expect C source code being pasted in, say, Word be compiled, linked and run from there automagically?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
jpomalley

To All,

jchd thanks for your note. I did read your answer, and also the section of help that you referred me to. However, after reviewing this information, I think your kind answer doesn't captures the essence of the problem I am having.

I have been causing the script to execute by setting the default action in Windows for an autoit file being clicked on to be "Run in autoit". This is working, because I have been executing other scripts this way successfully. Essentially windows is running the command-line command

autoit3.exe <script>

when the script is double-clicked on or run through a hotkey shortcut. This has successfully executed a number of different scripts that I have worked on so far successfully. It's just this one specific script that is showing odd behavior.

I think the analogy with pasting C source code into a text edit window is not quite what is happening here, or shouldn't be what is happening here, because I am not pasting source code from autoit into the text edit field. I am causing autoit to execute the code. If autoit is in fact pasting the source code for the script that I asked it to execute into the text edit field, I would be curious about why it is doing this.

One thought that I am having is, perhaps what is happening is the code is executing, but is experiencing some kind of error. Maybe the "Sleep(500)" that I see pasted into the text edit field is an incomplete portion of an error message that the system is trying to display? Perhaps I can play around with the error output to test this theory.

Thanks again to anyone who can offer any friendly help.

Joe

Share this post


Link to post
Share on other sites
Jos

How is your clipboard filled with information as you script only seems to do a paste operation ?

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
jchd

I am not pasting source code from autoit into the text edit field.

This is in contradiction with what you've already explained.

I am causing autoit to execute the code.

How is the question. You can only use ShellExecute (explicit or implicit) on some file with an extension linked to AutoIt.exe (generally .au3), that or use one of the more pedestrian method I've already exposed.

Pasting AutoIt code into an edit fireld, an editor (SciTE or else) can't cause execution.

I advise you post a reproducer script or procedure so that we actually understand what you're doing and what you're expecting to get. Until then things are clear as heavy mud and don't really make sense (at least to me).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
jpomalley

Sorry if things are muddy. Let me try to explain step by step what is happening:

-I have a file named "copy to ff.au3". This file contains the autoit script that I am trying to use.
-The contents of that file are as follows:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
MouseClick("left")
Sleep(500)
Send("^+r^w",0)
Sleep(500)
WinActivate("Mozilla Firefox")
Sleep(500)
Send("^v",0)

-I created a shortcut to the file, and put the shortcut on the desktop

-The default action for windows to take when opening .au3 files is "execute with autoit".

-I also assign a keyboard hotkey to that shortcut in windows. So when I press F5, the script should execute. This works with other scripts.

-I am utilizing software package (let's say "Private App"), that is not anything related to editing the script, it is an internal software package used in my company. This is a windows application that has a text edit field, and there is company data in that field. I frequently have to copy the contents of that field out of the Private App and paste it into a Firefox text edit field. I am seeking to automate the process of copying that text, switching into firefox, and pasting the text.

-To copy the contents of that text edit field in this app, they keystroke is ctrl-shift-r, though this is kind of nonstandard. Just imagine ctrl-a then ctrl-c. But it's ctrl-shift-r actually. Then close the window of Private App with ctrl-w, switch to firefox, and then paste the text

-Now, with the Private App running and foregrounded, and the caret in the text edit field I want to copy, and the mouse pointer hovering over that text edit field, I hit the F5 key.

-At first I didnt have the left mouse click in there, but it appears as the script runs the Private App is no longer foregrounded. So the first thing that happens is a mouse click to re-foreground the app. The script does appear to start executing as the Private App first loses its foregrounded status, and then regains it presumably due to MouseClick("left")

-When I ran the script without the Sleep(500) functions, it appeared to partly work - that is, it did copy the text out of the Private App and I confirmed it was on the clipboard. However, it did not activate firefox. Sometimes it closed the window, but not reliably. When I manually checked the contents of the clipboard, it appears the ctrl-shift-r did work.

-I theorized that perhaps it was working partially but not fully because it takes some time for my requested events to occur. I.e., to copy the text, close the window, switch to firefox, and rather than have everything go as rapidly as possible one keystroke after another, I should insert pauses.

-Then, I added the Sleep(500) statements that you see in the script. Heretofor, the script was exactly as is listed above but without the Sleep(500) lines.

-Now, when I hit F5 to run the script, what happens is the Private App loses foreground status, then regains it (you can tell from the window title bar, etc.), and then the text

Sleep(500)

is pasted into the active text edit field of Private App, adding the string Sleep(500) to the company information that was already in that field. It is pasted only once and nothing else happens.

That's the part that is really perplexing me. The script is executing, I am not sure why autoit would paste source code from a script it is currently trying to execute into the currently active text edit field. I am wondering at this point if it is perhaps an error message that is only partially printing out, perhaps just the first line of the error message? That could make sense.

Thanks, hopefully that is clearer, appreciate any help.

Joe

 

Edited by jpomalley

Share this post


Link to post
Share on other sites
jchd

Waooo, that complicated. First, using Send() is utterly reliable, just as you've experienced. You should use a real compiled script to do all the work for you. WinWaitActive, WinActivate, ControlSend, etc. are your best friends. Then also use the FF UDF or do it with the _IE functions. Remove all your keyboard shortcuts as I can imagine some have conflicting behavior in more than one active window. Use the AutoIt info tool to get information about window(s) and controls used in the private app, and HotKeySet to trigger the job.

Only then you'll have a reliable functional program to perform the task.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
jpomalley

Ok thanks. Understand your points about reliability and better methods of doing various things, which I will try.

Are you as stumped as me as to how the source code text "Sleep(500)" winds up getting pasted into Private App's text edit field?

That strikes me as quite odd and I'm at a loss to understand why it happens.

 

Share this post


Link to post
Share on other sites
jchd

It's more than likely a result of some hotkey combination being interpreted by SciTE or something else.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
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

×