Jump to content

Why doesn't my simple script work perfectly 100% of the time?


Recommended Posts

HotKeySet("{F1}", "LWTcopyAndPaste1")
HotKeySet("{F2}", "LWTcopyAndPaste1")
HotKeySet("{F3}", "LWTcopyAndPaste1")
HotKeySet("{F4}", "LWTcopyAndPaste1")

HotKeySet("{`}", "Ignore")

;HotKeySet("{ESCAPE}", "Terminate")

sleep(2000)

While 1
   sleep(10)

WEnd



Func LWTcopyAndPaste1()

   Local $englishString = ""

   ;get original mouse position
   $startPOSX = MouseGetPos(0);
   $startPOSY = MouseGetPos(1);

   ;copy highlighted english definition
   Sleep(5)
   Send("{CTRLDOWN}c{CTRLUP}")
   Sleep(5)
   $englishString = ClipGet()
   Sleep(5)

   ;paste to define box
   MouseMove(1130,200,0)
   Sleep(5)
   MouseClick("left")
   Sleep(5)
   Send("{CTRLDOWN}v{CTRLUP}")
   Sleep(5)

   ;save
   send("{ENTER}")
   Sleep(5)

   ;reposition mouse to start
   MouseMove($startPOSX,$startPOSY,0);
   ToolTip($englishString,650,247)
   
EndFunc

The script is pretty simple. Pressing F1-F4 copies highlighted text to a box then sends enter to save it.

The problem is sometimes it pastes things on the clipboard from the previous word meaning it did not copy. Since it saves so fast I do not even realize it made a mistake. That is why I had to add a ToolTip that is constantly on showing what was last saved. Trying to fix something saved incorrectly is very slow so I would like to find out how to stop this from messing up.

Link to comment
Share on other sites

Different applications require different length of presses to register...play with the AutoITSetOptions.  Also, send is sending at the active window, where sometimes, your mouse needs to be within the frame of that window...depends on the app.  You might rather look into controlsend (which is more accurate, but still has the issues with the application not registering the send)

100% - use ControlGetText...ControlSetText

or the DOM object if it's IE.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...