<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Работа с двумя окнами]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17710&amp;type=atom" />
	<updated>2023-04-11T19:00:14Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=17710</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157527#p157527" />
			<content type="html"><![CDATA[<p><a href="http://forum.script-coding.com/viewtopic.php?pid=157526#p157526">Добавил</a>.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-04-11T19:00:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157527#p157527</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157523#p157523" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Советую добавить <a href="http://forum.script-coding.com/viewtopic.php?pid=157369#p157369">этот код</a> в коллекцию (если его там ещё почему-то нет). Через поиск не обнаружил. Проверил на Win XP, 7, 10 и везде работает.</p>]]></content>
			<author>
				<name><![CDATA[__Михаил__]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=40928</uri>
			</author>
			<updated>2023-04-11T18:25:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157523#p157523</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157382#p157382" />
			<content type="html"><![CDATA[<p><strong>marusa122</strong>, я последний раз напомню про точку. Мне начинает казаться, что вы издеваетесь.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-03-23T20:40:05Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157382#p157382</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157381#p157381" />
			<content type="html"><![CDATA[<p>Всем спасибо за ответы. На англоязычном форуме подсказали простое, но гениальное решение. С моими коррективами скрипт получился таким:<br /></p><div class="codebox"><pre><code>:*:-25::
MouseMove, 1266, 663 ; перемещает мышку на координаты нужного числа (всегда одни и те же)
Click 2 ; выделяет это число
ClipSave=%ClipboardAll%
Clipboard= ;
Send, ^{c} ; копирует выделенный текст
ClipWait, 2
Result:=Round(Clipboard-25,2) ; делает вычисления и округляет число
MsgBox, 0, Итог, %Result%, ; показывает MsgBox с результатом
Clipboard=%ClipSave%
Return</code></pre></div><p>Здесь даже не пришлось добавлять деление на 100. При работе с Калькулятором число наподобие 999.00 копировалось и вставлялось как 99900, а в данном случае скрипт правильно воспринимает точку как разделитель.</p>]]></content>
			<author>
				<name><![CDATA[marusa122]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43077</uri>
			</author>
			<updated>2023-03-23T20:36:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157381#p157381</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157371#p157371" />
			<content type="html"><![CDATA[<p>А в реальности часто в степени приходится возводить? <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /> Там через Math.pow().<br />Вот monster.ahk:<br /></p><div class="codebox"><pre><code>MsgBox % Eval(&quot;3**3&quot;)

Eval(x) {                              ; non-recursive PRE/POST PROCESSING: I/O forms, numbers, ops, &quot;;&quot;
   Local FORM, FormF, FormI, i, W, y, y1, y2, y3, y4
   FormI := A_FormatInteger, FormF := A_FormatFloat

   SetFormat Integer, D                ; decimal intermediate results!
   RegExMatch(x, &quot;\$(b|h|x|)(\d*[eEgG]?)&quot;, y)
   FORM := y1, W := y2                 ; HeX, Bin, .{digits} output format
   SetFormat FLOAT, 0.16e              ; Full intermediate float precision
   StringReplace x, x, %y%             ; remove $..
   Loop
      If RegExMatch(x, &quot;i)(.*)(0x[a-f\d]*)(.*)&quot;, y)
         x := y1 . y2+0 . y3           ; convert hex numbers to decimal
      Else Break
   Loop
      If RegExMatch(x, &quot;(.*)&#039;([01]*)(.*)&quot;, y)
         x := y1 . FromBin(y2) . y3    ; convert binary numbers to decimal: sign = first bit
      Else Break
   x := RegExReplace(x,&quot;(^|[^.\d])(\d+)(e|E)&quot;,&quot;$1$2.$3&quot;) ; add missing &#039;.&#039; before E (1e3 -&gt; 1.e3)
                                       ; literal scientific numbers between ‘ and ’ chars
   x := RegExReplace(x,&quot;(\d*\.\d*|\d)([eE][+-]?\d+)&quot;,&quot;‘$1$2’&quot;)

   StringReplace x, x,`%, \, All       ; %  -&gt; \ (= MOD)
   StringReplace x, x, **,@, All       ; ** -&gt; @ for easier process
   StringReplace x, x, +, ±, All       ; ± is addition
   x := RegExReplace(x,&quot;(‘[^’]*)±&quot;,&quot;$1+&quot;) ; ...not inside literal numbers
   StringReplace x, x, -, ¬, All       ; ¬ is subtraction
   x := RegExReplace(x,&quot;(‘[^’]*)¬&quot;,&quot;$1-&quot;) ; ...not inside literal numbers

   Loop Parse, x, `;
      y := Eval1(A_LoopField)          ; work on pre-processed sub expressions
                                       ; return result of last sub-expression (numeric)
   If FORM = b                         ; convert output to binary
      y := W ? ToBinW(Round(y),W) : ToBin(Round(y))
   Else If (FORM=&quot;h&quot; or FORM=&quot;x&quot;) {
      SetFormat Integer, Hex           ; convert output to hex
      y := Round(y) + 0
   }
   Else {
      W := W=&quot;&quot; ? &quot;0.6g&quot; : &quot;0.&quot; . W    ; Set output form, Default = 6 decimal places
      SetFormat FLOAT, %W%
      y += 0.0
   }
   SetFormat Integer, %FormI%          ; restore original formats
   SetFormat FLOAT,   %FormF%
   Return y
}

Eval1(x) {                             ; recursive PREPROCESSING of :=, vars, (..) [decimal, no &quot;;&quot;]
   Local i, y, y1, y2, y3
                                       ; save function definition: f(x) := expr
   If RegExMatch(x, &quot;(\S*?)\((.*?)\)\s*:=\s*(.*)&quot;, y) {
      f%y1%__X := y2, f%y1%__F := y3
      Return
   }
                                       ; execute leftmost &quot;:=&quot; operator of a := b := ...
   If RegExMatch(x, &quot;(\S*?)\s*:=\s*(.*)&quot;, y) {
      y := &quot;x&quot; . y1                    ; user vars internally start with x to avoid name conflicts
      Return %y% := Eval1(y2)
   }
                                       ; here: no variable to the left of last &quot;:=&quot;
   x := RegExReplace(x,&quot;([\)’.\w]\s+|[\)’])([a-z_A-Z]+)&quot;,&quot;$1«$2»&quot;)  ; op -&gt; «op»

   x := RegExReplace(x,&quot;\s+&quot;)          ; remove spaces, tabs, newlines

   x := RegExReplace(x,&quot;([a-z_A-Z]\w*)\(&quot;,&quot;&#039;$1&#039;(&quot;) ; func( -&gt; &#039;func&#039;( to avoid atan|tan conflicts

   x := RegExReplace(x,&quot;([a-z_A-Z]\w*)([^\w&#039;»’]|$)&quot;,&quot;%x$1%$2&quot;) ; VAR -&gt; %xVAR%
   x := RegExReplace(x,&quot;(‘[^’]*)%x[eE]%&quot;,&quot;$1e&quot;) ; in numbers %xe% -&gt; e
   x := RegExReplace(x,&quot;‘|’&quot;)          ; no more need for number markers
   Transform x, Deref, %x%             ; dereference all right-hand-side %var%-s

   Loop {                              ; find last innermost (..)
      If RegExMatch(x, &quot;(.*)\(([^\(\)]*)\)(.*)&quot;, y)
         x := y1 . Eval@(y2) . y3      ; replace (x) with value of x
      Else Break
   }
   Return Eval@(x)
}

Eval@(x) {                             ; EVALUATE PRE-PROCESSED EXPRESSIONS [decimal, NO space, vars, (..), &quot;;&quot;, &quot;:=&quot;]
   Local i, y, y1, y2, y3, y4

   If x is number                      ; no more operators left
      Return x
                                       ; execute rightmost ?,: operator
   RegExMatch(x, &quot;(.*)(\?|:)(.*)&quot;, y)
   IfEqual y2,?,  Return Eval@(y1) ? Eval@(y3) : &quot;&quot;
   IfEqual y2,:,  Return ((y := Eval@(y1)) = &quot;&quot; ? Eval@(y3) : y)

   StringGetPos i, x, ||, R            ; execute rightmost || operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) || Eval@(SubStr(x,3+i))
   StringGetPos i, x, &amp;&amp;, R            ; execute rightmost &amp;&amp; operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) &amp;&amp; Eval@(SubStr(x,3+i))
                                       ; execute rightmost =, &lt;&gt; operator
   RegExMatch(x, &quot;(.*)(?&lt;![\&lt;\&gt;])(\&lt;\&gt;|=)(.*)&quot;, y)
   IfEqual y2,=,  Return Eval@(y1) =  Eval@(y3)
   IfEqual y2,&lt;&gt;, Return Eval@(y1) &lt;&gt; Eval@(y3)
                                       ; execute rightmost &lt;,&gt;,&lt;=,&gt;= operator
   RegExMatch(x, &quot;(.*)(?&lt;![\&lt;\&gt;])(\&lt;=?|\&gt;=?)(?![\&lt;\&gt;])(.*)&quot;, y)
   IfEqual y2,&lt;,  Return Eval@(y1) &lt;  Eval@(y3)
   IfEqual y2,&gt;,  Return Eval@(y1) &gt;  Eval@(y3)
   IfEqual y2,&lt;=, Return Eval@(y1) &lt;= Eval@(y3)
   IfEqual y2,&gt;=, Return Eval@(y1) &gt;= Eval@(y3)
                                       ; execute rightmost user operator (low precedence)
   RegExMatch(x, &quot;i)(.*)«(.*?)»(.*)&quot;, y)
   If IsFunc(y2)
      Return %y2%(Eval@(y1),Eval@(y3)) ; predefined relational ops

   StringGetPos i, x, |, R             ; execute rightmost | operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) | Eval@(SubStr(x,2+i))
   StringGetPos i, x, ^, R             ; execute rightmost ^ operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) ^ Eval@(SubStr(x,2+i))
   StringGetPos i, x, &amp;, R             ; execute rightmost &amp; operator
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) &amp; Eval@(SubStr(x,2+i))
                                       ; execute rightmost &lt;&lt;, &gt;&gt; operator
   RegExMatch(x, &quot;(.*)(\&lt;\&lt;|\&gt;\&gt;)(.*)&quot;, y)
   IfEqual y2,&lt;&lt;, Return Eval@(y1) &lt;&lt; Eval@(y3)
   IfEqual y2,&gt;&gt;, Return Eval@(y1) &gt;&gt; Eval@(y3)
                                       ; execute rightmost +- (not unary) operator
   RegExMatch(x, &quot;(.*[^!\~±¬\@\*/\\])(±|¬)(.*)&quot;, y) ; lower precedence ops already handled
   IfEqual y2,±,  Return Eval@(y1) + Eval@(y3)
   IfEqual y2,¬,  Return Eval@(y1) - Eval@(y3)
                                       ; execute rightmost */% operator
   RegExMatch(x, &quot;(.*)(\*|/|\\)(.*)&quot;, y)
   IfEqual y2,*,  Return Eval@(y1) * Eval@(y3)
   IfEqual y2,/,  Return Eval@(y1) / Eval@(y3)
   IfEqual y2,\,  Return Mod(Eval@(y1),Eval@(y3))
                                       ; execute rightmost power
   StringGetPos i, x, @, R
   IfGreaterOrEqual i,0, Return Eval@(SubStr(x,1,i)) ** Eval@(SubStr(x,2+i))
                                       ; execute rightmost function, unary operator
   If !RegExMatch(x,&quot;(.*)(!|±|¬|~|&#039;(.*)&#039;)(.*)&quot;, y)
      Return x                         ; no more function (y1 &lt;&gt; &quot;&quot; only at multiple unaries: --+-)
   IfEqual y2,!,Return Eval@(y1 . !y4) ; unary !
   IfEqual y2,±,Return Eval@(y1 .  y4) ; unary +
   IfEqual y2,¬,Return Eval@(y1 . -y4) ; unary - (they behave like functions)
   IfEqual y2,~,Return Eval@(y1 . ~y4) ; unary ~
   If IsFunc(y3)
      Return Eval@(y1 . %y3%(y4))      ; built-in and predefined functions(y4)
   Return Eval@(y1 . Eval1(RegExReplace(f%y3%__F, f%y3%__X, y4))) ; LAST: user defined functions
}

ToBin(n) {      ; Binary representation of n. 1st bit is SIGN: -8 -&gt; 1000, -1 -&gt; 1, 0 -&gt; 0, 8 -&gt; 01000
   Return n=0||n=-1 ? -n : ToBin(n&gt;&gt;1) . n&amp;1
}
ToBinW(n,W=8) { ; LS W-bits of Binary representation of n
   Loop %W%     ; Recursive (slower): Return W=1 ? n&amp;1 : ToBinW(n&gt;&gt;1,W-1) . n&amp;1
      b := n&amp;1 . b, n &gt;&gt;= 1
   Return b
}
FromBin(bits) { ; Number converted from the binary &quot;bits&quot; string, 1st bit is SIGN
   n = 0
   Loop Parse, bits
      n += n + A_LoopField
   Return n - (SubStr(bits,1,1)&lt;&lt;StrLen(bits))
}

Sgn(x) {
   Return (x&gt;0)-(x&lt;0)
}

MIN(a,b) {
   Return a&lt;b ? a : b
}
MAX(a,b) {
   Return a&lt;b ? b : a
}
GCD(a,b) {      ; Euclidean GCD
   Return b=0 ? Abs(a) : GCD(b, mod(a,b))
}
Choose(n,k) {   ; Binomial coefficient
   p := 1, i := 0, k := k &lt; n-k ? k : n-k
   Loop %k%                   ; Recursive (slower): Return k = 0 ? 1 : Choose(n-1,k-1)*n//k
      p *= (n-i)/(k-i), i+=1  ; FOR INTEGERS: p *= n-i, p //= ++i
   Return Round(p)
}

Fib(n) {        ; n-th Fibonacci number (n &lt; 0 OK, iterative to avoid globals)
   a := 0, b := 1
   Loop % abs(n)-1
      c := b, b += a, a := c
   Return n=0 ? 0 : n&gt;0 || n&amp;1 ? b : -b
}
fac(n) {        ; n!
   Return n&lt;2 ? 1 : n*fac(n-1)
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-03-23T17:53:25Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157371#p157371</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157370#p157370" />
			<content type="html"><![CDATA[<p>Не, не проще:<br /></p><div class="codebox"><pre><code>MsgBox, % Calc(&quot;3**3&quot;)

Calc(expr) {
   try res := GetJS().eval(expr)
   catch {
      MsgBox, Incorrect expression
      Return
   }
   Return res
}

GetJS() {
   static Doc, JS
   if !Doc {
      Doc := ComObjCreate(&quot;htmlfile&quot;)
      Doc.write(&quot;&lt;meta http-equiv=&quot;&quot;X-UA-Compatible&quot;&quot; content=&quot;&quot;IE=9&quot;&quot;&gt;&quot;)
      JS := Doc.parentWindow
      ( Doc.documentMode &lt; 9 &amp;&amp; JS.execScript() )
   }
   Return JS
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2023-03-23T17:46:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157370#p157370</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157369#p157369" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>MsgBox, % Calc(&quot;3*(5-25)&quot;)

Calc(expr) {
   try res := GetJS().eval(expr)
   catch {
      MsgBox, Incorrect expression
      Return
   }
   Return res
}

GetJS() {
   static Doc, JS
   if !Doc {
      Doc := ComObjCreate(&quot;htmlfile&quot;)
      Doc.write(&quot;&lt;meta http-equiv=&quot;&quot;X-UA-Compatible&quot;&quot; content=&quot;&quot;IE=9&quot;&quot;&gt;&quot;)
      JS := Doc.parentWindow
      ( Doc.documentMode &lt; 9 &amp;&amp; JS.execScript() )
   }
   Return JS
}</code></pre></div><p>Так не проще?<br />Но тот <a href="https://www.autohotkey.com/board/topic/15675-monster-evaluate-math-expressions-in-strings/">Monster.ahk</a> работал без создания дополнительных объектов, просто парсингом.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-03-23T17:44:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157369#p157369</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157368#p157368" />
			<content type="html"><![CDATA[<p>А зачем формулы составлять?<br /></p><div class="codebox"><pre><code>js := new JsRT.Edge
MsgBox % js.Eval(&quot;3*(5-25)&quot;)


/*
 *  ActiveScript for AutoHotkey v1.1
 *
 *  Provides an interface to Active Scripting languages like VBScript and JScript,
 *  without relying on Microsoft&#039;s ScriptControl, which is not available to 64-bit
 *  programs.
 *
 *  License: Use, modify and redistribute without limitation, but at your own risk.
 */
class ActiveScript extends ActiveScript._base
{
    __New(Language)
    {
        if this._script := ComObjCreate(Language, ActiveScript.IID)
            this._scriptParse := ComObjQuery(this._script, ActiveScript.IID_Parse)
        if !this._scriptParse
            throw Exception(&quot;Invalid language&quot;, -1, Language)
        this._site := new ActiveScriptSite(this)
        this._SetScriptSite(this._site.ptr)
        this._InitNew()
        this._objects := {}
        this.Error := &quot;&quot;
        this._dsp := this._GetScriptDispatch()  ; Must be done last.
        try
            if this.ScriptEngine() = &quot;JScript&quot;
                this.SetJScript58()
    }

    SetJScript58()
    {
        static IID_IActiveScriptProperty := &quot;{4954E0D0-FBC7-11D1-8410-006008C3FBFC}&quot;
        if !prop := ComObjQuery(this._script, IID_IActiveScriptProperty)
            return false
        VarSetCapacity(var, 24, 0), NumPut(2, NumPut(3, var, &quot;short&quot;) + 6)
        hr := DllCall(NumGet(NumGet(prop+0)+4*A_PtrSize), &quot;ptr&quot;, prop, &quot;uint&quot;, 0x4000
            , &quot;ptr&quot;, 0, &quot;ptr&quot;, &amp;var), ObjRelease(prop)
        return hr &gt;= 0
    }
    
    Eval(Code)
    {
        pvar := NumGet(ComObjValue(arr:=ComObjArray(0xC,1)) + 8+A_PtrSize)
        this._ParseScriptText(Code, 0x20, pvar)  ; SCRIPTTEXT_ISEXPRESSION := 0x20
        return arr[0]
    }
    
    Exec(Code)
    {
        this._ParseScriptText(Code, 0x42, 0)  ; SCRIPTTEXT_ISVISIBLE := 2, SCRIPTTEXT_ISPERSISTENT := 0x40
        this._SetScriptState(2)  ; SCRIPTSTATE_CONNECTED := 2
    }
    
    AddObject(Name, DispObj, AddMembers := false)
    {
        static a, supports_dispatch ; Test for built-in IDispatch support.
            := a := ((a:=ComObjArray(0xC,1))[0]:=[42]) &amp;&amp; a[0][1]=42
        if IsObject(DispObj) &amp;&amp; !(supports_dispatch || ComObjType(DispObj))
            throw Exception(&quot;Adding a non-COM object requires AutoHotkey v1.1.17+&quot;, -1)
        this._objects[Name] := DispObj
        this._AddNamedItem(Name, AddMembers ? 8 : 2)  ; SCRIPTITEM_ISVISIBLE := 2, SCRIPTITEM_GLOBALMEMBERS := 8
    }
    
    _GetObjectUnk(Name)
    {
        return !IsObject(dsp := this._objects[Name]) ? dsp  ; Pointer
            : ComObjValue(dsp) ? ComObjValue(dsp)  ; ComObject
            : &amp;dsp  ; AutoHotkey object
    }
    
    class _base
    {
        __Call(Method, Params*)
        {
            if ObjHasKey(this, &quot;_dsp&quot;)
                try
                    return (this._dsp)[Method](Params*)
                catch e
                    throw Exception(e.Message, -1, e.Extra)
        }
        
        __Get(Property, Params*)
        {
            if ObjHasKey(this, &quot;_dsp&quot;)
                try
                    return (this._dsp)[Property, Params*]
                catch e
                    throw Exception(e.Message, -1, e.Extra)
        }
        
        __Set(Property, Params*)
        {
            if ObjHasKey(this, &quot;_dsp&quot;)
            {
                Value := Params.Pop()
                try
                    return (this._dsp)[Property, Params*] := Value
                catch e
                    throw Exception(e.Message, -1, e.Extra)
            }
        }
    }
    
    _SetScriptSite(Site)
    {
        hr := DllCall(NumGet(NumGet((p:=this._script)+0)+3*A_PtrSize), &quot;ptr&quot;, p, &quot;ptr&quot;, Site)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScript::SetScriptSite&quot;)
    }
    
    _SetScriptState(State)
    {
        hr := DllCall(NumGet(NumGet((p:=this._script)+0)+5*A_PtrSize), &quot;ptr&quot;, p, &quot;int&quot;, State)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScript::SetScriptState&quot;)
    }
    
    _AddNamedItem(Name, Flags)
    {
        hr := DllCall(NumGet(NumGet((p:=this._script)+0)+8*A_PtrSize), &quot;ptr&quot;, p, &quot;wstr&quot;, Name, &quot;uint&quot;, Flags)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScript::AddNamedItem&quot;)
    }
    
    _GetScriptDispatch()
    {
        hr := DllCall(NumGet(NumGet((p:=this._script)+0)+10*A_PtrSize), &quot;ptr&quot;, p, &quot;ptr&quot;, 0, &quot;ptr*&quot;, pdsp)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScript::GetScriptDispatch&quot;)
        return ComObject(9, pdsp, 1)
    }
    
    _InitNew()
    {
        hr := DllCall(NumGet(NumGet((p:=this._scriptParse)+0)+3*A_PtrSize), &quot;ptr&quot;, p)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScriptParse::InitNew&quot;)
    }
    
    _ParseScriptText(Code, Flags, pvarResult)
    {
        VarSetCapacity(excp, 8 * A_PtrSize, 0)
        hr := DllCall(NumGet(NumGet((p:=this._scriptParse)+0)+5*A_PtrSize), &quot;ptr&quot;, p
            , &quot;wstr&quot;, Code, &quot;ptr&quot;, 0, &quot;ptr&quot;, 0, &quot;ptr&quot;, 0, &quot;uptr&quot;, 0, &quot;uint&quot;, 1
            , &quot;uint&quot;, Flags, &quot;ptr&quot;, pvarResult, &quot;ptr&quot;, 0)
        if (hr &lt; 0)
            this._HRFail(hr, &quot;IActiveScriptParse::ParseScriptText&quot;)
    }
    
    _HRFail(hr, what)
    {
        if e := this.Error
        {
            this.Error := &quot;&quot;
            throw Exception(&quot;`nError code:`t&quot; this._HRFormat(e.HRESULT)
                . &quot;`nSource:`t`t&quot; e.Source &quot;`nDescription:`t&quot; e.Description
                . &quot;`nLine:`t`t&quot; e.Line &quot;`nColumn:`t`t&quot; e.Column
                . &quot;`nLine text:`t`t&quot; e.LineText, -3)
        }
        throw Exception(what &quot; failed with code &quot; this._HRFormat(hr), -2)
    }
    
    _HRFormat(hr)
    {
        return Format(&quot;0x{1:X}&quot;, hr &amp; 0xFFFFFFFF)
    }
    
    _OnScriptError(err) ; IActiveScriptError err
    {
        VarSetCapacity(excp, 8 * A_PtrSize, 0)
        DllCall(NumGet(NumGet(err+0)+3*A_PtrSize), &quot;ptr&quot;, err, &quot;ptr&quot;, &amp;excp) ; GetExceptionInfo
        DllCall(NumGet(NumGet(err+0)+4*A_PtrSize), &quot;ptr&quot;, err, &quot;uint*&quot;, srcctx, &quot;uint*&quot;, srcline, &quot;int*&quot;, srccol) ; GetSourcePosition
        DllCall(NumGet(NumGet(err+0)+5*A_PtrSize), &quot;ptr&quot;, err, &quot;ptr*&quot;, pbstrcode) ; GetSourceLineText
        code := StrGet(pbstrcode, &quot;UTF-16&quot;), DllCall(&quot;OleAut32\SysFreeString&quot;, &quot;ptr&quot;, pbstrcode)
        if fn := NumGet(excp, 6 * A_PtrSize) ; pfnDeferredFillIn
            DllCall(fn, &quot;ptr&quot;, &amp;excp)
        wcode := NumGet(excp, 0, &quot;ushort&quot;)
        hr := wcode ? 0x80040200 + wcode : NumGet(excp, 7 * A_PtrSize, &quot;uint&quot;)
        this.Error := {HRESULT: hr, Line: srcline, Column: srccol, LineText: code}
        static Infos := &quot;Source,Description,HelpFile&quot;
        Loop Parse, % Infos, `,
            if pbstr := NumGet(excp, A_Index * A_PtrSize)
                this.Error[A_LoopField] := StrGet(pbstr, &quot;UTF-16&quot;), DllCall(&quot;OleAut32\SysFreeString&quot;, &quot;ptr&quot;, pbstr)
        return 0x80004001 ; E_NOTIMPL (let Exec/Eval get a fail result)
    }
    
    __Delete()
    {
        if this._script
        {
            DllCall(NumGet(NumGet((p:=this._script)+0)+7*A_PtrSize), &quot;ptr&quot;, p)  ; Close
            ObjRelease(this._script)
        }
        if this._scriptParse
            ObjRelease(this._scriptParse)
    }
    
    static IID := &quot;{BB1A2AE1-A4F9-11cf-8F20-00805F2CD064}&quot;
    static IID_Parse := A_PtrSize=8 ? &quot;{C7EF7658-E1EE-480E-97EA-D52CB4D76D17}&quot; : &quot;{BB1A2AE2-A4F9-11cf-8F20-00805F2CD064}&quot;
}

class ActiveScriptSite
{
    __New(Script)
    {
        ObjSetCapacity(this, &quot;_site&quot;, 3 * A_PtrSize)
        NumPut(&amp;Script
        , NumPut(ActiveScriptSite._vftable(&quot;_vft_w&quot;, &quot;31122&quot;, 0x100)
        , NumPut(ActiveScriptSite._vftable(&quot;_vft&quot;, &quot;31125232211&quot;, 0)
            , this.ptr := ObjGetAddress(this, &quot;_site&quot;))))
    }
    
    _vftable(Name, PrmCounts, EIBase)
    {
        if p := ObjGetAddress(this, Name)
            return p
        ObjSetCapacity(this, Name, StrLen(PrmCounts) * A_PtrSize)
        p := ObjGetAddress(this, Name)
        Loop Parse, % PrmCounts
        {
            cb := RegisterCallback(&quot;_ActiveScriptSite&quot;, &quot;F&quot;, A_LoopField, A_Index + EIBase)
            NumPut(cb, p + (A_Index-1) * A_PtrSize)
        }
        return p
    }
}

_ActiveScriptSite(this, a1:=0, a2:=0, a3:=0, a4:=0, a5:=0)
{
    Method := A_EventInfo &amp; 0xFF
    if A_EventInfo &gt;= 0x100  ; IActiveScriptSiteWindow
    {
        if Method = 4  ; GetWindow
        {
            NumPut(0, a1+0) ; *phwnd := 0
            return 0 ; S_OK
        }
        if Method = 5  ; EnableModeless
        {
            return 0 ; S_OK
        }
        this -= A_PtrSize     ; Cast to IActiveScriptSite
    }
    ;else: IActiveScriptSite
    if Method = 1  ; QueryInterface
    {
        iid := _AS_GUIDToString(a1)
        if (iid = &quot;{00000000-0000-0000-C000-000000000046}&quot;  ; IUnknown
         || iid = &quot;{DB01A1E3-A42B-11cf-8F20-00805F2CD064}&quot;) ; IActiveScriptSite
        {
            NumPut(this, a2+0)
            return 0 ; S_OK
        }
        if (iid = &quot;{D10F6761-83E9-11cf-8F20-00805F2CD064}&quot;) ; IActiveScriptSiteWindow
        {
            NumPut(this + A_PtrSize, a2+0)
            return 0 ; S_OK
        }
        NumPut(0, a2+0)
        return 0x80004002 ; E_NOINTERFACE
    }
    if Method = 5  ; GetItemInfo
    {
        a1 := StrGet(a1, &quot;UTF-16&quot;)
        , (a3 &amp;&amp; NumPut(0, a3+0))  ; *ppiunkItem := NULL
        , (a4 &amp;&amp; NumPut(0, a4+0))  ; *ppti := NULL
        if (a2 &amp; 1) ; SCRIPTINFO_IUNKNOWN
        {
            if !(unk := Object(NumGet(this + A_PtrSize*2))._GetObjectUnk(a1))
                return 0x8002802B ; TYPE_E_ELEMENTNOTFOUND
            ObjAddRef(unk), NumPut(unk, a3+0)
        }
        return 0 ; S_OK
    }
    if Method = 9  ; OnScriptError
        return Object(NumGet(this + A_PtrSize*2))._OnScriptError(a1)
    
    ; AddRef and Release don&#039;t do anything because we want to avoid circular references.
    ; The site and IActiveScript are both released when the AHK script releases its last
    ; reference to the ActiveScript object.
    
    ; All of the other methods don&#039;t require implementations.
    return 0x80004001 ; E_NOTIMPL
}

_AS_GUIDToString(pGUID)
{
    VarSetCapacity(String, 38*2)
    DllCall(&quot;ole32\StringFromGUID2&quot;, &quot;ptr&quot;, pGUID, &quot;str&quot;, String, &quot;int&quot;, 39)
    return String
}


/*
 *  JsRT for AutoHotkey v1.1
 *
 *  Utilizes the JavaScript engine that comes with IE11.
 *
 *  License: Use, modify and redistribute without limitation, but at your own risk.
 */
class JsRT extends ActiveScript._base
{
    __New()
    {
        throw Exception(&quot;This class is abstract. Use JsRT.IE or JSRT.Edge instead.&quot;, -1)
    }
    
    class IE extends JsRT
    {
        __New()
        {
            if !this._hmod := DllCall(&quot;LoadLibrary&quot;, &quot;str&quot;, &quot;jscript9&quot;, &quot;ptr&quot;)
                throw Exception(&quot;Failed to load jscript9.dll&quot;, -1)
            if DllCall(&quot;jscript9\JsCreateRuntime&quot;, &quot;int&quot;, 0, &quot;int&quot;, -1
                , &quot;ptr&quot;, 0, &quot;ptr*&quot;, runtime) != 0
                throw Exception(&quot;Failed to initialize JsRT&quot;, -1)
            DllCall(&quot;jscript9\JsCreateContext&quot;, &quot;ptr&quot;, runtime, &quot;ptr&quot;, 0, &quot;ptr*&quot;, context)
            this._Initialize(&quot;jscript9&quot;, runtime, context)
        }
    }
    
    class Edge extends JsRT
    {
        __New()
        {
            if !this._hmod := DllCall(&quot;LoadLibrary&quot;, &quot;str&quot;, &quot;chakra&quot;, &quot;ptr&quot;)
                throw Exception(&quot;Failed to load chakra.dll&quot;, -1)
            if DllCall(&quot;chakra\JsCreateRuntime&quot;, &quot;int&quot;, 0
                , &quot;ptr&quot;, 0, &quot;ptr*&quot;, runtime) != 0
                throw Exception(&quot;Failed to initialize JsRT&quot;, -1)
            DllCall(&quot;chakra\JsCreateContext&quot;, &quot;ptr&quot;, runtime, &quot;ptr*&quot;, context)
            this._Initialize(&quot;chakra&quot;, runtime, context)
        }
        
        ProjectWinRTNamespace(namespace)
        {
            return DllCall(&quot;chakra\JsProjectWinRTNamespace&quot;, &quot;wstr&quot;, namespace)
        }
    }
    
    _Initialize(dll, runtime, context)
    {
        this._dll := dll
        this._runtime := runtime
        this._context := context
        DllCall(dll &quot;\JsSetCurrentContext&quot;, &quot;ptr&quot;, context)
        DllCall(dll &quot;\JsGetGlobalObject&quot;, &quot;ptr*&quot;, globalObject)
        this._dsp := this._JsToVt(globalObject)
    }
    
    __Delete()
    {
        this._dsp := &quot;&quot;
        if dll := this._dll
        {
            DllCall(dll &quot;\JsSetCurrentContext&quot;, &quot;ptr&quot;, 0)
            DllCall(dll &quot;\JsDisposeRuntime&quot;, &quot;ptr&quot;, this._runtime)
        }
        DllCall(&quot;FreeLibrary&quot;, &quot;ptr&quot;, this._hmod)
    }
    
    _JsToVt(valref)
    {
        VarSetCapacity(variant, 24, 0)
        DllCall(this._dll &quot;\JsValueToVariant&quot;, &quot;ptr&quot;, valref, &quot;ptr&quot;, &amp;variant)
        ref := ComObject(0x400C, &amp;variant), val := ref[], ref[] := 0
        return val
    }
    
    _ToJs(val)
    {
        VarSetCapacity(variant, 24, 0)
        ref := ComObject(0x400C, &amp;variant) ; VT_BYREF|VT_VARIANT
        ref[] := val
        DllCall(this._dll &quot;\JsVariantToValue&quot;, &quot;ptr&quot;, &amp;variant, &quot;ptr*&quot;, valref)
        ref[] := 0
        return valref
    }
    
    _JsEval(code)
    {
        e := DllCall(this._dll &quot;\JsRunScript&quot;, &quot;wstr&quot;, code, &quot;uptr&quot;, 0, &quot;wstr&quot;, &quot;source.js&quot;
            , &quot;ptr*&quot;, result)
        if e
        {
            if DllCall(this._dll &quot;\JsGetAndClearException&quot;, &quot;ptr*&quot;, excp) = 0
                throw this._JsToVt(excp)
            throw Exception(&quot;JsRT error&quot;, -2, format(&quot;0x{:X}&quot;, e))
        }
        return result
    }
    
    Exec(code)
    {
        this._JsEval(code)
    }
    
    Eval(code)
    {
        return this._JsToVt(this._JsEval(code))
    }
    
    AddObject(name, obj, addMembers := false)
    {
        if addMembers
            throw Exception(&quot;AddMembers=true is not supported&quot;, -1)
        this._dsp[name] := obj
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2023-03-23T17:12:48Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157368#p157368</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157367#p157367" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>marusa122 пишет:</cite><blockquote><p>Вопрос: а может ли AutoHotkey считать сам, без &quot;костылей&quot; в виде Калькулятора?</p></blockquote></div><p>Может. Составляйте формулы из переменных.<br /></p><div class="codebox"><pre><code>
a:=3
b:=5
c:=a*(b-25)
msgbox,% &quot;a=&quot; a &quot;`nb=&quot; b &quot;`nc=&quot; c</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alectric]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26027</uri>
			</author>
			<updated>2023-03-23T14:43:50Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157367#p157367</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157362#p157362" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>marusa122 пишет:</cite><blockquote><p>На этапе &quot;вставляет число&quot; скрипт ничего не вставляет.</p></blockquote></div><p>После Send, ^{c} (где фигурные скобки не нужны), выделенный текст не сразу попадает в буфер обмена, соответственно, у вас в переменной прошлое его значение. Нужно перед посылом Ctrl + C очистить буфер обмена, присвоив ему пустое значение, а после посыла ждать появления информации с помощью ClipWait.<br /></p><div class="quotebox"><cite>marusa122 пишет:</cite><blockquote><p>а может ли AutoHotkey считать сам, без &quot;костылей&quot; в виде Калькулятора?</p></blockquote></div><p>Сам не может, но есть различные библиотеки. Я помню, была такая Monster.ahk, которая умела парсить строку с математическим выражением и выдавать результат, гуглите.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-03-22T19:25:28Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157362#p157362</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157361#p157361" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, да какой из меня программист... Вернула точку.</p>]]></content>
			<author>
				<name><![CDATA[marusa122]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43077</uri>
			</author>
			<updated>2023-03-22T19:12:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157361#p157361</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157360#p157360" />
			<content type="html"><![CDATA[<p>Вы не очень внимательны, да? В программировании это нежелательное качество. <img src="//forum.script-coding.com/img/smilies/wink.png" width="15" height="15" /><br /></p><div class="quotebox"><cite>marusa122 пишет:</cite><blockquote><p>Вернула, извините</p></blockquote></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-03-22T18:46:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157360#p157360</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157359#p157359" />
			<content type="html"><![CDATA[<p>Вернула, извините.</p>]]></content>
			<author>
				<name><![CDATA[marusa122]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43077</uri>
			</author>
			<updated>2023-03-22T18:36:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157359#p157359</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157358#p157358" />
			<content type="html"><![CDATA[<p>Точки верните на своё место, пожалуйста.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2023-03-22T18:30:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157358#p157358</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Работа с двумя окнами]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=157357#p157357" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, вот <br /></p><div class="codebox"><pre><code>:*:-25::
CoordMode, Mouse, Screen
MouseMove, 1266, 663 ; перемещается к числу в окне браузера
Click 2 ; выделяет число
tempClip := Clipboard
Send, ^{c}
copiedText := Clipboard
Clipboard := tempClip
Run calc.exe ; открывает Калькулятор
Sleep, 5000
Send, %copiedText% ; вставляет число
Click 320, 403 ; поделить
Send 100 ; на 100
Click 319, 615 ; равно
Click 320, 519 ; минус
Send 25 
Click 319, 615 ; равно
return</code></pre></div><p>На этапе &quot;вставляет число&quot; скрипт ничего не вставляет. Все операции проводятся с 0.<br />Или принимает координаты за числа, с которыми надо работать.<br />Вопрос: а может ли AutoHotkey считать сам, без &quot;костылей&quot; в виде Калькулятора?</p>]]></content>
			<author>
				<name><![CDATA[marusa122]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43077</uri>
			</author>
			<updated>2023-03-22T17:52:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=157357#p157357</id>
		</entry>
</feed>
