<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.returnofreckoning.com/index.php?action=history&amp;feed=atom&amp;title=API%3AWindowAssignFocus</id>
	<title>API:WindowAssignFocus - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.returnofreckoning.com/index.php?action=history&amp;feed=atom&amp;title=API%3AWindowAssignFocus"/>
	<link rel="alternate" type="text/html" href="https://wiki.returnofreckoning.com/index.php?title=API:WindowAssignFocus&amp;action=history"/>
	<updated>2026-10-17T17:54:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://wiki.returnofreckoning.com/index.php?title=API:WindowAssignFocus&amp;diff=30862&amp;oldid=prev</id>
		<title>Maintenance script: UI Lua API import (WAR 1.4.8)</title>
		<link rel="alternate" type="text/html" href="https://wiki.returnofreckoning.com/index.php?title=API:WindowAssignFocus&amp;diff=30862&amp;oldid=prev"/>
		<updated>2026-10-16T19:51:19Z</updated>

		<summary type="html">&lt;p&gt;UI Lua API import (WAR 1.4.8)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{LuaApi|group=Window}}&lt;br /&gt;
Gives keyboard focus to a window, or takes it away.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WindowAssignFocus(windowName, focus)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arguments ==&lt;br /&gt;
;windowName : &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt; – Name of the window, typically a TextEditBox.&lt;br /&gt;
;focus : &amp;lt;code&amp;gt;boolean&amp;lt;/code&amp;gt; – &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; to give the window focus, &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; to take it away.&lt;br /&gt;
&lt;br /&gt;
== Returns ==&lt;br /&gt;
Nothing.&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
* With &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;, the window must currently be drawn on screen. Show it (and its parents) first, otherwise the call raises the &amp;#039;&amp;#039;is not visible&amp;#039;&amp;#039; error.&lt;br /&gt;
* With &amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt;, there is no visibility check.&lt;br /&gt;
* &amp;lt;code&amp;gt;focus&amp;lt;/code&amp;gt; must be a real boolean. Passing &amp;lt;code&amp;gt;nil&amp;lt;/code&amp;gt; or a number raises an &amp;#039;&amp;#039;Invalid Parameters&amp;#039;&amp;#039; error.&lt;br /&gt;
* The function needs at least two arguments and only reads the last two.&lt;br /&gt;
&lt;br /&gt;
== Errors ==&lt;br /&gt;
* &amp;lt;code&amp;gt;Error in function call &amp;#039;WindowAssignFocus&amp;#039;: Window %s does not exist&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;Error in function call &amp;#039;WindowAssignFocus&amp;#039;: Window %s is not visible. You may not set focus to a window that is not currently being drawn on the screen.&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;Error in function call &amp;#039;WindowAssignFocus&amp;#039;: Window %s is currently locked and may not be modified from lua. ...&amp;lt;/code&amp;gt;&amp;lt;br/&amp;gt;This check never triggers in the current client. See [[API:WindowSetShowing|WindowSetShowing]].&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
Showing a text entry dialog and focusing its edit box, from &amp;lt;code&amp;gt;easystem_dialogmanager/source/dialogmanager.lua&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Finally, show the dialog.&lt;br /&gt;
WindowSetShowing( &amp;quot;TextEntryDlg&amp;quot;..dlgIndex, true )&lt;br /&gt;
WindowAssignFocus( &amp;quot;TextEntryDlg&amp;quot;..dlgIndex..&amp;quot;TextEntry&amp;quot;, true )&lt;br /&gt;
TextEditBoxSelectAll( &amp;quot;TextEntryDlg&amp;quot;..dlgIndex..&amp;quot;TextEntry&amp;quot; )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Releasing the focus when the dialog is closed, same file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- Ideally this should be done automatically when the window is hidden, but whatever.&lt;br /&gt;
WindowAssignFocus( &amp;quot;TextEntryDlg&amp;quot;..dlgIndex..&amp;quot;TextEntry&amp;quot;, false )&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[API:WindowSetShowing|WindowSetShowing]]&lt;br /&gt;
* [[API:WindowSetTabOrder|WindowSetTabOrder]]&lt;/div&gt;</summary>
		<author><name>Maintenance script</name></author>
	</entry>
</feed>