snipt

Ctrl+h for KB shortcuts

Python

Using the Macro Scheduler SDK in Python

from ctypes import *

#load the library
lib = WinDLL('mscript.dll')

#initialise ...
lib.Init()

#create an output buffer
sRes = create_unicode_buffer(1024)

#image recognition code to click on Windows Start Button
code = u"""//Find and Left Click Center of
Let>bmp=C:\\Users\Marcus\\Documents\\Macro Scheduler 14\\DLL\\image_1.bmp
Mdl>This is version: %MSCHED_VER%
FindImagePos>bmp,SCREEN,0,1,XArr,YArr,NumFound,EXACT
If>NumFound>0
  MouseMove>XArr_0,YArr_0
  LClick
Endif
"""

#run the code
n = lib.RunCode(code,u"",sRes,1024)

lib.Cleanup()

Description

Using the MacroScript (Macro Scheduler) SDK within Python to create a simple screen image recognition macro.
https://snipt.net/embed/76f6cd41bf6b70ff1b4a3c3f8ac83891/
/raw/76f6cd41bf6b70ff1b4a3c3f8ac83891/
76f6cd41bf6b70ff1b4a3c3f8ac83891
python
Python
26
2019-07-16T10:01:20
True
False
False
Oct 14, 2014 at 10:12 AM
/api/public/snipt/136738/
using-the-macro-scheduler-sdk-in-python-890d0b99
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a> <a href="#L-16">16</a> <a href="#L-17">17</a> <a href="#L-18">18</a> <a href="#L-19">19</a> <a href="#L-20">20</a> <a href="#L-21">21</a> <a href="#L-22">22</a> <a href="#L-23">23</a> <a href="#L-24">24</a> <a href="#L-25">25</a> <a href="#L-26">26</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kn">from</span> <span class="nn">ctypes</span> <span class="kn">import</span> <span class="o">*</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1">#load the library</span> </span><span id="L-4"><a name="L-4"></a><span class="n">lib</span> <span class="o">=</span> <span class="n">WinDLL</span><span class="p">(</span><span class="s1">&#39;mscript.dll&#39;</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="c1">#initialise ...</span> </span><span id="L-7"><a name="L-7"></a><span class="n">lib</span><span class="o">.</span><span class="n">Init</span><span class="p">()</span> </span><span id="L-8"><a name="L-8"></a> </span><span id="L-9"><a name="L-9"></a><span class="c1">#create an output buffer</span> </span><span id="L-10"><a name="L-10"></a><span class="n">sRes</span> <span class="o">=</span> <span class="n">create_unicode_buffer</span><span class="p">(</span><span class="mi">1024</span><span class="p">)</span> </span><span id="L-11"><a name="L-11"></a> </span><span id="L-12"><a name="L-12"></a><span class="c1">#image recognition code to click on Windows Start Button</span> </span><span id="L-13"><a name="L-13"></a><span class="n">code</span> <span class="o">=</span> <span class="s2">u&quot;&quot;&quot;//Find and Left Click Center of</span> </span><span id="L-14"><a name="L-14"></a><span class="s2">Let&gt;bmp=C:</span><span class="se">\\</span><span class="s2">Users\Marcus</span><span class="se">\\</span><span class="s2">Documents</span><span class="se">\\</span><span class="s2">Macro Scheduler 14</span><span class="se">\\</span><span class="s2">DLL</span><span class="se">\\</span><span class="s2">image_1.bmp</span> </span><span id="L-15"><a name="L-15"></a><span class="s2">Mdl&gt;This is version: %MSCHED_VER%</span> </span><span id="L-16"><a name="L-16"></a><span class="s2">FindImagePos&gt;bmp,SCREEN,0,1,XArr,YArr,NumFound,EXACT</span> </span><span id="L-17"><a name="L-17"></a><span class="s2">If&gt;NumFound&gt;0</span> </span><span id="L-18"><a name="L-18"></a><span class="s2"> MouseMove&gt;XArr_0,YArr_0</span> </span><span id="L-19"><a name="L-19"></a><span class="s2"> LClick</span> </span><span id="L-20"><a name="L-20"></a><span class="s2">Endif</span> </span><span id="L-21"><a name="L-21"></a><span class="s2">&quot;&quot;&quot;</span> </span><span id="L-22"><a name="L-22"></a> </span><span id="L-23"><a name="L-23"></a><span class="c1">#run the code</span> </span><span id="L-24"><a name="L-24"></a><span class="n">n</span> <span class="o">=</span> <span class="n">lib</span><span class="o">.</span><span class="n">RunCode</span><span class="p">(</span><span class="n">code</span><span class="p">,</span><span class="s2">u&quot;&quot;</span><span class="p">,</span><span class="n">sRes</span><span class="p">,</span><span class="mi">1024</span><span class="p">)</span> </span><span id="L-25"><a name="L-25"></a> </span><span id="L-26"><a name="L-26"></a><span class="n">lib</span><span class="o">.</span><span class="n">Cleanup</span><span class="p">()</span> </span></pre></div> </td></tr></table>
"Macro Scheduler", MacroScript, Python