Class: AutoItX3::Edit

Inherits:
Control show all
Defined in:
lib/AutoItX3/control.rb

Overview

An edit control is a single- or multiline input control in which you can type text. For example, notepad consists mainly of a big edit control.

Instance Method Summary collapse

Methods inherited from Control

#click, #disable, #enable, #enabled?, #focus, from_control, functions, functions=, #handle, #hide, #initialize, #move, #rect, #send_command_to_control, #send_keys, #show, #text, #text=, #visible?

Constructor Details

This class inherits a constructor from AutoItX3::Control

Instance Method Details

#caret_posObject

Returns the current caret position.

Return value

A 2-element array of form [line, column]. Numbering starts with 1.

Raises

Au3Error

Control or window not found.

Example

p edit.caret_pos #=> [1, 1]


533
534
535
536
537
# File 'lib/AutoItX3/control.rb', line 533

def caret_pos
  x = send_command_to_control("GetCurrentLine").to_i
  y = send_command_to_control("GetCurrentCol").to_i
  [x, y]
end

#linesObject

Returns the number of lines in self.

Return value

The number of lines.

Raises

Au3Error

Control or window not found.

Example

p edit.lines #=> 3


546
547
548
# File 'lib/AutoItX3/control.rb', line 546

def lines
  send_command_to_control("GetLineCount").to_i
end

#paste(str) ⇒ Object

“Pastes” str at self‘s current caret position.

Parameters

str

The text to paste.

Return value

Unknown.

Example

edit.paste("My text")

Remarks

In contrast to #selected_text, the window should receive the text correctly, since AutoItX3 only accepts UTF-16LE-encoded strings.



573
574
575
# File 'lib/AutoItX3/control.rb', line 573

def paste(str)
  send_command_to_control("EditPaste", str)
end

#selected_textObject

Returns the currently selected text.

Return value

The currently selected text selection.

Example

p edit.selected_text #=> "I love Ruby!"

Remarks

Be careful with the encoding of the returned text. It’s likely that you have to do a force_encoding on it, since there isn’t any guarantee in which encoding a window returns it’s contents.



559
560
561
# File 'lib/AutoItX3/control.rb', line 559

def selected_text
  send_command_to_control("GetSelected")
end