<?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: Matlab callbacks for uifigure JavaScript events	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=matlab-callbacks-for-uifigure-javascript-events</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Mon, 03 Apr 2023 06:05:09 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Ba		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comment-520968</link>

		<dc:creator><![CDATA[Ba]]></dc:creator>
		<pubDate>Mon, 03 Apr 2023 06:05:09 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7913#comment-520968</guid>

					<description><![CDATA[Dear Iliya,
remove uibutton, instead of using the &quot;WindowButtonDownFcn&quot; of uifigure is working for me.]]></description>
			<content:encoded><![CDATA[<p>Dear Iliya,<br />
remove uibutton, instead of using the &#8220;WindowButtonDownFcn&#8221; of uifigure is working for me.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Manu		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comment-501509</link>

		<dc:creator><![CDATA[Manu]]></dc:creator>
		<pubDate>Fri, 04 Oct 2019 16:26:27 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7913#comment-501509</guid>

					<description><![CDATA[Hi,

thanks very much for this code. Working perfectly for me on a uiimage object which I use to display a tiled map (like OpenStreetMap).
Since I needed more possible interactions than just the default MATLAB &quot;ImageClicked&quot; callback, this came as the perfect solution!

Thanks again, great work.]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>thanks very much for this code. Working perfectly for me on a uiimage object which I use to display a tiled map (like OpenStreetMap).<br />
Since I needed more possible interactions than just the default MATLAB &#8220;ImageClicked&#8221; callback, this came as the perfect solution!</p>
<p>Thanks again, great work.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Perttu		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comment-454673</link>

		<dc:creator><![CDATA[Perttu]]></dc:creator>
		<pubDate>Sun, 02 Dec 2018 17:29:35 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7913#comment-454673</guid>

					<description><![CDATA[Hi,

I don&#039;t know if this is &quot;general knowledge&quot; but you can turn  on debugging by running:
 &lt;pre lang=&quot;matlab&quot;&gt;matlab.internal.webwindow(&#039;http://example.com&#039;, &#039;DebugPort&#039;, 4040)&lt;/pre&gt;
 before any other App, or kill all MatlabWindow applications (from task manager) before the command. Then go with Chrome to http://localhost:4040/]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>I don&#8217;t know if this is &#8220;general knowledge&#8221; but you can turn  on debugging by running:</p>
<pre lang="matlab">matlab.internal.webwindow('http://example.com', 'DebugPort', 4040)</pre>
<p> before any other App, or kill all MatlabWindow applications (from task manager) before the command. Then go with Chrome to <a href="http://localhost:4040/" rel="nofollow ugc">http://localhost:4040/</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Iliya		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comment-437203</link>

		<dc:creator><![CDATA[Iliya]]></dc:creator>
		<pubDate>Fri, 24 Aug 2018 12:38:21 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7913#comment-437203</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comment-437037&quot;&gt;Khris Griffis&lt;/a&gt;.

Hi Khris,

⁬

Thanks for sharing your attempt (and thoughts) regarding the key press listeners! I&#039;m sure it would be a helpful starting point for those who would like to explore this direction further. If you have a suggestion regarding how to add this functionality to &lt;code&gt;mlapptools&lt;/code&gt; in a way that would be convenient for the user - please don&#039;t hesitate to &lt;a href=&quot;https://github.com/StackOverflowMATLABchat/mlapptools/issues&quot; rel=&quot;nofollow&quot;&gt;open an issue&lt;/a&gt; in the repo and/or drop us a line in &lt;a href=&quot;https://chat.stackoverflow.com/rooms/81987/chatlab-and-talktave&quot; rel=&quot;nofollow&quot;&gt;chat&lt;/a&gt;. We&#039;d be happy to hear feedback regarding any existing (or missing) functionality, and ideas about alternative implementations.
⁬

All the best,
Iliya.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comment-437037">Khris Griffis</a>.</p>
<p>Hi Khris,</p>
<p>⁬</p>
<p>Thanks for sharing your attempt (and thoughts) regarding the key press listeners! I&#8217;m sure it would be a helpful starting point for those who would like to explore this direction further. If you have a suggestion regarding how to add this functionality to <code>mlapptools</code> in a way that would be convenient for the user &#8211; please don&#8217;t hesitate to <a href="https://github.com/StackOverflowMATLABchat/mlapptools/issues" rel="nofollow">open an issue</a> in the repo and/or drop us a line in <a href="https://chat.stackoverflow.com/rooms/81987/chatlab-and-talktave" rel="nofollow">chat</a>. We&#8217;d be happy to hear feedback regarding any existing (or missing) functionality, and ideas about alternative implementations.<br />
⁬</p>
<p>All the best,<br />
Iliya.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Khris Griffis		</title>
		<link>https://undocumentedmatlab.com/articles/matlab-callbacks-for-uifigure-javascript-events#comment-437037</link>

		<dc:creator><![CDATA[Khris Griffis]]></dc:creator>
		<pubDate>Thu, 23 Aug 2018 18:34:32 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=7913#comment-437037</guid>

					<description><![CDATA[Great workaround Iliya! 

I was playing with something similar to this, though my approach was not as nice. I found that we can add listeners to the DOM for key presses and then use javascript (&lt;code&gt;document.querySelector([id=&quot;uniqName_##_#&quot;]&#039;).click()&lt;/code&gt;) to initiate a button press on an invisible button, which then fires the matlab callback for the .ButtonPushedFcn. Essentially doing what you&#039;ve done here for mouse clicks but for keyboard presses. I haven&#039;t extensively tested it, but the following function works to spit out keypresses into the command window (only tested on 2018a).

I&#039;m sure there are better ways to capture the keypress information (dojo/keys perhaps) and I would assume it&#039;s possible to capture keypresses in defined contexts, like when a text area is active or when the mouse is hovering over an element, but I haven&#039;t really tested this extensively.

Cheers,
Khris

&lt;pre lang=&quot;matlab&quot;&gt;
function [f,b,w] = testkey()
  f = uifigure;
  b = uibutton(f,&#039;Visible&#039;,  &#039;off&#039;);
  [w,bid] = mlapptools.getWebElements(b);
  
  function clickCallback(s,e)
    %callback for button press gets keypress text and displays in console.
    tx = w.executeJS(&#039;tK&#039;);
    disp(tx)
  end

  b.ButtonPushedFcn = @(s,e)clickCallback(s,e);
  bqry = sprintf(&#039;document.querySelector(&#039;&#039;[%s=&quot;%s&quot;]&#039;&#039;)&#039;, ...
    bid.ID_attr, ...
    bid.ID_val ...
    );
  
  jstext = [ ...
    &#039;var tK = &quot;&quot;, &#039;, ...
    &#039;but = %s;&#039;, ...
    &#039;document.addEventListener(&#039;&#039;keypress&#039;&#039;, function(e){&#039;, ...
    &#039;  tK = &quot;&quot;;&#039;,...
    &#039;  if (e.altKey) tK += &#039;&#039;ALT+&#039;&#039;;&#039;,...
    &#039;  if (e.ctrlKey) tK += &#039;&#039;CTRL+&#039;&#039;;&#039;,...
    &#039;  if (e.metaKey) tK += &#039;&#039;META+&#039;&#039;;&#039;,...
    &#039;  if (e.shiftKey) tK += &#039;&#039;SHIFT+&#039;&#039;;&#039;,...
    &#039;  tK += e.key;&#039;,...
    &#039;  but.click(); &#039; ...
    &#039;});&#039; ...
  ];

  w.executeJS(sprintf(jstext,bqry));
end
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Great workaround Iliya! </p>
<p>I was playing with something similar to this, though my approach was not as nice. I found that we can add listeners to the DOM for key presses and then use javascript (<code>document.querySelector([id="uniqName_##_#"]').click()</code>) to initiate a button press on an invisible button, which then fires the matlab callback for the .ButtonPushedFcn. Essentially doing what you&#8217;ve done here for mouse clicks but for keyboard presses. I haven&#8217;t extensively tested it, but the following function works to spit out keypresses into the command window (only tested on 2018a).</p>
<p>I&#8217;m sure there are better ways to capture the keypress information (dojo/keys perhaps) and I would assume it&#8217;s possible to capture keypresses in defined contexts, like when a text area is active or when the mouse is hovering over an element, but I haven&#8217;t really tested this extensively.</p>
<p>Cheers,<br />
Khris</p>
<pre lang="matlab">
function [f,b,w] = testkey()
  f = uifigure;
  b = uibutton(f,'Visible',  'off');
  [w,bid] = mlapptools.getWebElements(b);
  
  function clickCallback(s,e)
    %callback for button press gets keypress text and displays in console.
    tx = w.executeJS('tK');
    disp(tx)
  end

  b.ButtonPushedFcn = @(s,e)clickCallback(s,e);
  bqry = sprintf('document.querySelector(''[%s="%s"]'')', ...
    bid.ID_attr, ...
    bid.ID_val ...
    );
  
  jstext = [ ...
    'var tK = "", ', ...
    'but = %s;', ...
    'document.addEventListener(''keypress'', function(e){', ...
    '  tK = "";',...
    '  if (e.altKey) tK += ''ALT+'';',...
    '  if (e.ctrlKey) tK += ''CTRL+'';',...
    '  if (e.metaKey) tK += ''META+'';',...
    '  if (e.shiftKey) tK += ''SHIFT+'';',...
    '  tK += e.key;',...
    '  but.click(); ' ...
    '});' ...
  ];

  w.executeJS(sprintf(jstext,bqry));
end
</pre>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
