<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: GUI automation using a Robot	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/gui-automation-robot/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/gui-automation-robot?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gui-automation-robot</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Fri, 19 May 2023 13:45:17 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-521626</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 19 May 2023 13:45:17 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-521626</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/gui-automation-robot#comment-521616&quot;&gt;Elsa Smith&lt;/a&gt;.

Robot only runs when you tell it to run a command such as keyPress. If you don&#039;t tell it to run a command, it uses no CPU, so there&#039;s no need to remove the Robot object from memory. You just need to ensure that it doesn&#039;t keep running commands continuously, in some kind of loop. 

To simulate an ESCAPE key press, run &lt;code&gt;robot.keyPress(java.awt.event.KeyEvent.VK_ESCAPE);
robot.keyRelease(java.awt.event.KeyEvent.VK_ESCAPE);&lt;/code&gt; in your Matlab code.

Instead of simulating an ESCAPE key-press, you can also simulate a mouse-up event: &lt;code&gt;robot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);&lt;/code&gt;

You can also directly call the Figure&#039;s WindowButtonUpFcn callback function to invoke imfreehand&#039;s exit method without needing to use Robot: &lt;code&gt;hFig.WindowButtonUpFcn(hFig,[])&lt;/code&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/gui-automation-robot#comment-521616">Elsa Smith</a>.</p>
<p>Robot only runs when you tell it to run a command such as keyPress. If you don&#8217;t tell it to run a command, it uses no CPU, so there&#8217;s no need to remove the Robot object from memory. You just need to ensure that it doesn&#8217;t keep running commands continuously, in some kind of loop. </p>
<p>To simulate an ESCAPE key press, run <code>robot.keyPress(java.awt.event.KeyEvent.VK_ESCAPE);<br />
robot.keyRelease(java.awt.event.KeyEvent.VK_ESCAPE);</code> in your Matlab code.</p>
<p>Instead of simulating an ESCAPE key-press, you can also simulate a mouse-up event: <code>robot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);</code></p>
<p>You can also directly call the Figure&#8217;s WindowButtonUpFcn callback function to invoke imfreehand&#8217;s exit method without needing to use Robot: <code>hFig.WindowButtonUpFcn(hFig,[])</code></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Elsa Smith		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-521617</link>

		<dc:creator><![CDATA[Elsa Smith]]></dc:creator>
		<pubDate>Thu, 18 May 2023 11:47:10 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-521617</guid>

					<description><![CDATA[I recently used java.awt.Robot to perform GUI testing on MATLAB and found it to be an extremely easy and useful way to control mouse movements.]]></description>
			<content:encoded><![CDATA[<p>I recently used java.awt.Robot to perform GUI testing on MATLAB and found it to be an extremely easy and useful way to control mouse movements.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Elsa Smith		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-521616</link>

		<dc:creator><![CDATA[Elsa Smith]]></dc:creator>
		<pubDate>Thu, 18 May 2023 11:19:24 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-521616</guid>

					<description><![CDATA[I&#039;m suspecting that the slow performance of my GUI may be due to the use of java.awt.Robot. Is there a way to cancel/stop/remove the robot after it has been created, or is there an alternative way to simulate an ESCAPE button press to cancel drawing using imfreehand tool without using a Robot that involves a click of some kind?]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m suspecting that the slow performance of my GUI may be due to the use of java.awt.Robot. Is there a way to cancel/stop/remove the robot after it has been created, or is there an alternative way to simulate an ESCAPE button press to cancel drawing using imfreehand tool without using a Robot that involves a click of some kind?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: maiky76		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-513320</link>

		<dc:creator><![CDATA[maiky76]]></dc:creator>
		<pubDate>Sun, 30 Jan 2022 01:06:08 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-513320</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/gui-automation-robot#comment-513301&quot;&gt;maiky76&lt;/a&gt;.

I figured it out eventually. To my knowledge this is the only public example: &lt;a href=&quot;https://octave.discourse.group/t/help-on-java-keyevent/2163/14&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://octave.discourse.group/t/help-on-java-keyevent/2163/14&lt;/a&gt;

&lt;pre lang=&quot;matlab&quot;&gt;
robot   = javaObject(&quot;java.awt.Robot&quot;);
wait1   = robot.delay(500);
VKeight = java_get (&#039;java.awt.event.KeyEvent&#039;,&#039;VK_8&#039;);
a1      = javaMethod (&#039;keyPress&#039;, robot, VKeight);
a2      = javaMethod (&#039;keyRelease&#039;, robot, VKeight); 
&lt;/pre&gt;
etc...]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/gui-automation-robot#comment-513301">maiky76</a>.</p>
<p>I figured it out eventually. To my knowledge this is the only public example: <a href="https://octave.discourse.group/t/help-on-java-keyevent/2163/14" target="_blank" rel="nofollow">https://octave.discourse.group/t/help-on-java-keyevent/2163/14</a></p>
<pre lang="matlab">
robot   = javaObject("java.awt.Robot");
wait1   = robot.delay(500);
VKeight = java_get ('java.awt.event.KeyEvent','VK_8');
a1      = javaMethod ('keyPress', robot, VKeight);
a2      = javaMethod ('keyRelease', robot, VKeight); 
</pre>
<p>etc&#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: maiky76		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-513301</link>

		<dc:creator><![CDATA[maiky76]]></dc:creator>
		<pubDate>Fri, 28 Jan 2022 17:34:20 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-513301</guid>

					<description><![CDATA[Hi, 

The original post got me up and running in no time. Thank you so much!
I have been trying to translate what I did in Octave to share the code with others but I can&#039;t get it to work. 

Would anyone be gracious enough to give it a try?

Here is the code that behaves as I’d like it to:
Open external program, return to Octave script, Octave makes some keyboard inputs closes the program, then back to Octave to finish the remaining commands of the script

&lt;pre lang=&quot;matlab&quot;&gt;
clear all
close all
clc

if exist(&#039;OCTAVE_VERSION&#039;, &#039;builtin&#039;) == 0
 % Matlab version   
        import java.awt.*;
        import java.awt.event.*;

        system(&#039;&quot;calc.exe&quot;&#038;&#039;);

        R2D2 = Robot;
        R2D2.delay(100) 
        R2D2.keyPress(KeyEvent.VK_8)
        R2D2.keyRelease(KeyEvent.VK_8)
        R2D2.delay(500)  
    %     R2D2.keyPress(KeyEvent.VK_PLUS) % does not work!
    %    R2D2.keyRelease(KeyEvent.VK_PLUS) 
        R2D2.keyPress(KeyEvent.VK_DIVIDE)
        R2D2.keyRelease(KeyEvent.VK_DIVIDE)
        R2D2.delay(500) 
        R2D2.keyPress(KeyEvent.VK_2)
        R2D2.keyRelease(KeyEvent.VK_2)
        R2D2.delay(500) 
        R2D2.keyPress(KeyEvent.VK_ENTER)
        R2D2.keyRelease(KeyEvent.VK_ENTER)
        R2D2.delay(1000) 
        R2D2.keyPress(KeyEvent.VK_ALT)
        R2D2.keyPress(KeyEvent.VK_F4)
        R2D2.keyRelease(KeyEvent.VK_ALT)
        R2D2.keyRelease(KeyEvent.VK_F4)
      else
% Octave Version not working 
% OBJ = java_set (OBJ, NAME, VAL)
% obj = javaObject (classname, arg1, …)
% Ret = javaMethod (methodname, obj, arg1, …)  
% There is no import function so we need to express the full qualifier
% https://savannah.gnu.org/task/?12601

        system(&quot;calc.exe&quot;, false, &quot;async&quot;); 

        R2D2 = javaObject(&quot;java.awt.Robot&quot;); % works
        R2D2.delay(5000); % works
%        R2D2.keyPress(KeyEvent.VK_8)
%        javaMethod(&#039;KeyPress&#039;, R2D2, VK_ENTER)
%        javaMethod(&quot;KeyRelease&quot;, R2D2, &#039;VK_8&#039;)  
%        javaMethod(&#039;KeyPress&#039;, &#039;VK_ENTER&#039;)
%        R2D2.keyRelease(KeyEvent.VK_8)
  
%        R2D2.delay(500); 
%       javaMethod(&#039;KeyPress&#039;, R2D2, VK_PLUS)
%        javaMethod(&#039;KeyRelease&#039;, R2D2, VK_PLUS)
%        R2D2.delay(500); 
%        javaMethod(&#039;KeyPress&#039;, R2D2, VK_2)
%        javaMethod(&#039;KeyRelease&#039;, R2D2, VK_2)
%        R2D2.delay(500); 
%       javaMethod(&#039;KeyPress&#039;, R2D2, VK_ENTER)
%        javaMethod(&#039;KeyRelease&#039;, R2D2, VK_ENTER)
%      1+2
        
end
&lt;/pre&gt;

The reason why I am interested can we found here: &lt;a href=&quot;https://www.diyaudio.com/community/threads/acoustic-horn-design-the-easy-way-ath4.338806/page-459#post-6916828&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Acoustic Horn Design – The Easy Way (Ath4) &#124; Page 459 &#124; diyAudio)&lt;/a&gt;
We are trying to perform some optimization on the design of an DIY acoustic waveguide.
Any help would be much appreciated!]]></description>
			<content:encoded><![CDATA[<p>Hi, </p>
<p>The original post got me up and running in no time. Thank you so much!<br />
I have been trying to translate what I did in Octave to share the code with others but I can&#8217;t get it to work. </p>
<p>Would anyone be gracious enough to give it a try?</p>
<p>Here is the code that behaves as I’d like it to:<br />
Open external program, return to Octave script, Octave makes some keyboard inputs closes the program, then back to Octave to finish the remaining commands of the script</p>
<pre lang="matlab">
clear all
close all
clc

if exist('OCTAVE_VERSION', 'builtin') == 0
 % Matlab version   
        import java.awt.*;
        import java.awt.event.*;

        system('"calc.exe"&amp;');

        R2D2 = Robot;
        R2D2.delay(100) 
        R2D2.keyPress(KeyEvent.VK_8)
        R2D2.keyRelease(KeyEvent.VK_8)
        R2D2.delay(500)  
    %     R2D2.keyPress(KeyEvent.VK_PLUS) % does not work!
    %    R2D2.keyRelease(KeyEvent.VK_PLUS) 
        R2D2.keyPress(KeyEvent.VK_DIVIDE)
        R2D2.keyRelease(KeyEvent.VK_DIVIDE)
        R2D2.delay(500) 
        R2D2.keyPress(KeyEvent.VK_2)
        R2D2.keyRelease(KeyEvent.VK_2)
        R2D2.delay(500) 
        R2D2.keyPress(KeyEvent.VK_ENTER)
        R2D2.keyRelease(KeyEvent.VK_ENTER)
        R2D2.delay(1000) 
        R2D2.keyPress(KeyEvent.VK_ALT)
        R2D2.keyPress(KeyEvent.VK_F4)
        R2D2.keyRelease(KeyEvent.VK_ALT)
        R2D2.keyRelease(KeyEvent.VK_F4)
      else
% Octave Version not working 
% OBJ = java_set (OBJ, NAME, VAL)
% obj = javaObject (classname, arg1, …)
% Ret = javaMethod (methodname, obj, arg1, …)  
% There is no import function so we need to express the full qualifier
% https://savannah.gnu.org/task/?12601

        system("calc.exe", false, "async"); 

        R2D2 = javaObject("java.awt.Robot"); % works
        R2D2.delay(5000); % works
%        R2D2.keyPress(KeyEvent.VK_8)
%        javaMethod('KeyPress', R2D2, VK_ENTER)
%        javaMethod("KeyRelease", R2D2, 'VK_8')  
%        javaMethod('KeyPress', 'VK_ENTER')
%        R2D2.keyRelease(KeyEvent.VK_8)
  
%        R2D2.delay(500); 
%       javaMethod('KeyPress', R2D2, VK_PLUS)
%        javaMethod('KeyRelease', R2D2, VK_PLUS)
%        R2D2.delay(500); 
%        javaMethod('KeyPress', R2D2, VK_2)
%        javaMethod('KeyRelease', R2D2, VK_2)
%        R2D2.delay(500); 
%       javaMethod('KeyPress', R2D2, VK_ENTER)
%        javaMethod('KeyRelease', R2D2, VK_ENTER)
%      1+2
        
end
</pre>
<p>The reason why I am interested can we found here: <a href="https://www.diyaudio.com/community/threads/acoustic-horn-design-the-easy-way-ath4.338806/page-459#post-6916828" target="_blank" rel="nofollow">Acoustic Horn Design – The Easy Way (Ath4) | Page 459 | diyAudio)</a><br />
We are trying to perform some optimization on the design of an DIY acoustic waveguide.<br />
Any help would be much appreciated!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Joshua		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-416397</link>

		<dc:creator><![CDATA[Joshua]]></dc:creator>
		<pubDate>Tue, 14 Nov 2017 03:47:23 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-416397</guid>

					<description><![CDATA[Hi, is there a way to simulate the keyboard input using the robot when the robot encounters user input request generated? For example,
&lt;pre lang=&#039;matlab&#039;&gt;
a = input(&#039;Type a word: &#039;, &#039;s&#039;);
&lt;/pre&gt;
This is for the purpose of testing the interactive feature of a program. Is it possible?

Thanks!]]></description>
			<content:encoded><![CDATA[<p>Hi, is there a way to simulate the keyboard input using the robot when the robot encounters user input request generated? For example,</p>
<pre lang='matlab'>
a = input('Type a word: ', 's');
</pre>
<p>This is for the purpose of testing the interactive feature of a program. Is it possible?</p>
<p>Thanks!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Mayank		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-411492</link>

		<dc:creator><![CDATA[Mayank]]></dc:creator>
		<pubDate>Sat, 05 Aug 2017 13:01:00 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-411492</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/gui-automation-robot#comment-173195&quot;&gt;George&lt;/a&gt;.

create an int[] array for all the KeyEvent.Vk_1 to ..last then use the for loop to iterate over the same.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/gui-automation-robot#comment-173195">George</a>.</p>
<p>create an int[] array for all the KeyEvent.Vk_1 to ..last then use the for loop to iterate over the same.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: NSReddy		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-389119</link>

		<dc:creator><![CDATA[NSReddy]]></dc:creator>
		<pubDate>Sat, 24 Sep 2016 10:46:26 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-389119</guid>

					<description><![CDATA[Can u help me how to do the &quot; Alt+S&quot; using Robot Class]]></description>
			<content:encoded><![CDATA[<p>Can u help me how to do the &#8221; Alt+S&#8221; using Robot Class</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-373234</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 30 Mar 2016 07:55:46 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-373234</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/gui-automation-robot#comment-373169&quot;&gt;Apostolos Iliopoulos&lt;/a&gt;.

@Apostolos - the code as you wrote it just simulates pressing the &#060;Enter&#062; key so the key event will be sent to the currently-active window. If your editor is currently in focus then obviously the key event will be sent to it. If you want to send the key event to another window you must first ensure that the focus is on that window. There is no general way to do this, it is application-dependent.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/gui-automation-robot#comment-373169">Apostolos Iliopoulos</a>.</p>
<p>@Apostolos &#8211; the code as you wrote it just simulates pressing the &lt;Enter&gt; key so the key event will be sent to the currently-active window. If your editor is currently in focus then obviously the key event will be sent to it. If you want to send the key event to another window you must first ensure that the focus is on that window. There is no general way to do this, it is application-dependent.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Apostolos Iliopoulos		</title>
		<link>https://undocumentedmatlab.com/articles/gui-automation-robot#comment-373169</link>

		<dc:creator><![CDATA[Apostolos Iliopoulos]]></dc:creator>
		<pubDate>Tue, 29 Mar 2016 14:01:35 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1815#comment-373169</guid>

					<description><![CDATA[Very nice work!! 
But i have a problem. I would like to write a code which runs an executable file and then enter to programs window to create a new case. The code that I&#039;m using is this 
&lt;pre lang=&quot;matlab&quot;&gt;
system(&#039;w0315v11-64bit&#039;);
robot = java.awt.Robot;
robot.keyPress  (java.awt.event.KeyEvent.VK_ENTER);
robot.keyRelease(java.awt.event.KeyEvent.VK_ENTER); 
&lt;/pre&gt;

But instead of pressing enter on the programs window it presses it in the Matlab editor. 
Can you please tell me how to overcome this?
Thank you in advance]]></description>
			<content:encoded><![CDATA[<p>Very nice work!!<br />
But i have a problem. I would like to write a code which runs an executable file and then enter to programs window to create a new case. The code that I&#8217;m using is this </p>
<pre lang="matlab">
system('w0315v11-64bit');
robot = java.awt.Robot;
robot.keyPress  (java.awt.event.KeyEvent.VK_ENTER);
robot.keyRelease(java.awt.event.KeyEvent.VK_ENTER); 
</pre>
<p>But instead of pressing enter on the programs window it presses it in the Matlab editor.<br />
Can you please tell me how to overcome this?<br />
Thank you in advance</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
