Jump to content
Macro Express Forums

x-axis and Y-axis for Selected Text


Recommended Posts

Before you start selecting the text, ad command "Get Mouse Position" (Mouse) to save x-axis and y-axis into integer variable.

 

You can also use this code:

<MOUSE MOVE Option="\x01" X="611" Y="316" _PROMPT="0x000A"/>
<WAIT FOR LEFT MOUSE CLICK Indefinite="FALSE" Hours="0" Minutes="0" Seconds="10"/>
<GET MOUSE POSITION Option="\x00" X="%x_axis%" Y="%y_axis%"/>

How do you select the text? Double click, Ctr.+A or hold the mouse key down ?

 

Look_Up

Link to comment
Share on other sites

When text is selected in an Internet Explorer or Firefox window, there is no straightforward way to ascertain the x and y coordinates of the selection.

 

You might think this would help:

Mouse Move: To the Text Cursor Position

But it does not. In browsers, the position of selected text is NOT the same as the position of the text cursor. Instead, the text cursor is in the upper-left corner of the viewport.

 

The only way I know with MEP to get the coordinates of a selection on a web page is to hunt for pixel colours. I doubt it's possible to make these scripts 100% reliable. I have developed many such scripts; they take time and effort to work right. Usually tradeoffs are needed. For example, an MEP script to check every pixel on a screen may take several minutes to execute. To force these scripts to run acceptably fast, you might decide to choose to check a single vertical or horizontal line, a small region of the screen, or every five (or ten or hundred) pixels instead of every pixel. Or you might decide to manually move the mouse cursor nearby.

 

Here is an example of a MEP script that searches the 400 x 400 pixel region in the upper-left corner of a window:

// Search a 400 pixel by 400 pixel rectangular region for a colour
// Start at the top-left. Move right along a horizontal line, testing each pixel. At end of row, go to start of next line, and try again.
 
// Specify pixel colour to search for. Use "Mouse Locator" to obtain value.
Variable Set Integer %PixelTarget% to 7004146 // This colour appears in the ME Pro Script Editor, in the "M" icon to the left of "Macro Nickname:"
 
// Specify (x, y) of the top-left corner of the search rectangle...
Variable Set Integer %xStart% to 0
Variable Set Integer %yStart% to 0
 
// Specify (x, y) of the bottom-right corner of search rectangle...
Variable Set Integer %xEnd% to 400
Variable Set Integer %yEnd% to 400
 
// Calculate length and height of search rectangle:
Variable Modify Integer: %xLength% = %xEnd% - %xStart%
Variable Modify Integer: %yHeight% = %yEnd% - %yStart%
 
// Set coordinate to test. (Start in upper-left corner)...
Variable Set Integer %xCurrent% to %xStart%
Variable Set Integer %yCurrent% to %yStart%
 
// Start with the first "row" of pixels. We test up to yHeight rows...
Repeat Start (Repeat %yHeight% times)
// Test each pixel along a horizontal line xLength pixels long...
  Repeat Start (Repeat %xLength% times)
    Get Pixel Color at (%xCurrent%, %yCurrent%) Relative to Current Window into %PixelColour%
    If Variable %PixelColour% Does not Equal "%PixelTarget%"
    // Increment x so we test next pixel to the right...
      Variable Modify Integer %xCurrent%: Increment
    Else
    // Pixel found...
      Mouse Move: %xCurrent%, %yCurrent% Relative to Current Window
      Text Box Display: Found!
      Macro Stop
    End If
    // Continue until the entire row is tested...
  End Repeat
  // Reset x to its original value, and increment y so we can test pixels in the next row...
  Variable Set Integer %xCurrent% to %xStart%
  Variable Modify Integer %yCurrent%: Increment
End Repeat
 
// Pixel not found...
Mouse Move: %xEnd%, %yEnd% Relative to Current Window
Text Box Display: Not Found!

In theory, the script above can identify the upper-left coordinates of a selection, provided you identify its colour in advance, and assuming the selection appears within the specified 400 x 400 pixel region. To do this, the script loops up to 160,000 times. On my i7 computer, this takes over 40 seconds. So my script may not practical.

 

Perhaps others can suggest more efficient brute-force techniques.

Link to comment
Share on other sites

Hi Alan,

 

Thanks, I'd never previously noticed that failure of the Mouse Move: To the Text Cursor Position command when used in Firefox (my usual browser).

 

It does seem to work correctly in MSIE though.

 

Anyway, I'm not entirely clear about the OP's requirement. Crucially he doesn't say what browser he is using. But even for Firefox (or another browser in which the text cursor command fails), I think a simple Mouse move to say the RH side of the Search box followed by Shift+Home would do the job for me. That is providing I ensured a consistent size and position of the browser and any other factors, such as theme and Windows tray tabs etc.

 

Trickier scenarios include allowing for an unknown number of tab rows, which obviously displaces other 'main body' content.

 

--
Terry, East Grinstead, UK

Link to comment
Share on other sites

Hi Terry,

 

Move to Text Cursor Position does not work for me in Internet Explorer (Version 11). I tried it two ways: with caret browsing on and off. In both cases, the mouse cursor jumped to the upper left corner of the viewport.

 

Could there be an MSIE setting that controls this behaviour?

 

There are situations when mouse emulation is crucial, although the OP has not described the task in enough detail to determine whether it is the best course of action.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...