Core Function WinGetCaretPos
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> WinGetCaretPos ( ) </pre> === Description === Returns the coordinates of the caret in the foreground window. === Parameters === None === Return Value === Success: Re...") |
m (1 revision) |
||
(4 intermediate revisions by one user not shown) | |||
Line 41: | Line 41: | ||
{ | { | ||
my List ( $x_adjust = 5, $y_adjust = 40 ); | my List ( $x_adjust = 5, $y_adjust = 40 ); | ||
− | + | my $t = array(); | |
Opt("CaretCoordMode", 0); //relative mode | Opt("CaretCoordMode", 0); //relative mode | ||
Line 50: | Line 50: | ||
If ( isVarArray($c) && isVarArray($w) && isVarArray($e) ) | If ( isVarArray($c) && isVarArray($w) && isVarArray($e) ) | ||
− | + | { | |
$t[0] = $c[0] + $w[0] + $e[0] + $x_adjust; | $t[0] = $c[0] + $w[0] + $e[0] + $x_adjust; | ||
$t[1] = $c[1] + $w[1] + $e[1] + $y_adjust; | $t[1] = $c[1] + $w[1] + $e[1] + $y_adjust; | ||
Return $t; //absolute screen coords of caret cursor | Return $t; //absolute screen coords of caret cursor | ||
− | + | } | |
− | + | else | |
return 0; | return 0; | ||
} | } |
Latest revision as of 12:38, 14 June 2015
WinGetCaretPos ( )
Contents |
Description
Returns the coordinates of the caret in the foreground window.
Parameters
None
Return Value
Success: Returns a 2-element array containing the following information:
$array[0] = X coordinate $array[1] = Y coordinate
Failure: Returns 0.
Remarks
WinGetCaretPos might not return accurate values for Multiple Document Interface (MDI) applications if absolute CaretCoordMode is used.
See example for a workaround. Note: Some applications report static coordinates regardless of caret position!
Example
$a = WinGetCaretPos(); if($a) { println("First Method Pos $a[0], $a[1]"); } // More reliable method to get caret coords in MDI text editors. Function _CaretPos() { my List ( $x_adjust = 5, $y_adjust = 40 ); my $t = array(); Opt("CaretCoordMode", 0); //relative mode my $c = WinGetCaretPos(); //relative caret coords my $w = WinGetPos(""); //window's coords my $f = ControlGetFocus("",""); //text region "handle" my $e = ControlGetPos("", "", $f); //text region coords If ( isVarArray($c) && isVarArray($w) && isVarArray($e) ) { $t[0] = $c[0] + $w[0] + $e[0] + $x_adjust; $t[1] = $c[1] + $w[1] + $e[1] + $y_adjust; Return $t; //absolute screen coords of caret cursor } else return 0; }