<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: MXS: CreateDialog Enter/Escape Button in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480667#M6808</link>
    <description>&lt;P&gt;or make it more universal:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;fn createKeyboardAssembly =
(
	source = ""
	source += "using System;\n"
	source += "using System.Runtime.InteropServices;\n"
	source += "public class VirtualKeys\n"
	source += "{\n"
	source += "    const int KEY_PRESSED = 0x80;\n"
	source += "    [DllImport(\"user32.dll\", CharSet = CharSet.Auto, ExactSpelling = true)]\n"
	source += "    static extern short GetKeyState(int virtualKeyCode);\n"
	source += "    public bool IsKeyPressed(int key) { return (GetKeyState(key) &amp;amp; KEY_PRESSED) == KEY_PRESSED; }\n"
	source += "}\n"

	csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"

	compilerParams.ReferencedAssemblies.Add("System.dll");

	compilerParams.GenerateInMemory = true
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)

	compilerResults.CompiledAssembly
)

try(destroydialog warning_dialog) catch()
rollout warning_dialog "Warning" width:191
(
	local VK_ESCAPE = 0x1B
	local VK_RETURN = 0x0D
	local VK_SPACE  = 0x20

	local vk_assembly = createKeyboardAssembly()
	local vk = vk_assembly.CreateInstance "VirtualKeys"
	
	local result = #default

	label text_lb "Press ESC or ENTER..." align:#left
		
	timer quit_timer interval:10
	on quit_timer tick do
	(
		case of
		(
			(vk.IsKeyPressed(VK_ESCAPE)):
			(
				result = #escape
				destroydialog warning_dialog
			)
			(vk.IsKeyPressed(VK_RETURN)):
			(
				result = #ok
				destroydialog warning_dialog
			)
			(vk.IsKeyPressed(VK_SPACE)):
			(
				result = #space
				destroydialog warning_dialog
			)
		)
	)
		
	on warning_dialog close do
	(
		format "&amp;gt;&amp;gt; closed with %\n" result
	)
	on warning_dialog open do
	(
	)
)
createdialog warning_dialog modal:on escapeEnable:off&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 29 Apr 2020 18:55:00 GMT</pubDate>
    <dc:creator>denisT.MaxDoctor</dc:creator>
    <dc:date>2020-04-29T18:55:00Z</dc:date>
    <item>
      <title>MXS: CreateDialog Enter/Escape Button</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9476381#M6803</link>
      <description>&lt;P&gt;Is there any way to end a modal dialog via &amp;lt;Enter&amp;gt; or &amp;lt;Escape&amp;gt;?&lt;/P&gt;&lt;P&gt;"Default buttons" would have been great..&lt;/P&gt;&lt;P&gt;I use of course "escapeenable:false" to supress the error message..&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 13:05:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9476381#M6803</guid>
      <dc:creator>istan</dc:creator>
      <dc:date>2020-04-28T13:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: MXS: CreateDialog Enter/Escape Button</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9477288#M6804</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/203084"&gt;@istan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Is there any way to end a modal dialog via &amp;lt;Enter&amp;gt; or &amp;lt;Escape&amp;gt;?&lt;/P&gt;&lt;P&gt;"Default buttons" would have been great..&lt;/P&gt;&lt;P&gt;I use of course "escapeenable:false" to supress the error message..&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;end with &amp;lt;Escape&amp;gt; and "not escapable" at the same time? Sorry, but I don’t understand what you want from a modal dialog.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Apr 2020 17:09:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9477288#M6804</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2020-04-28T17:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: MXS: CreateDialog Enter/Escape Button</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9479882#M6805</link>
      <description>&lt;P&gt;a) I use "escapeenable:false" since I don't want to get an error message in the MXS listener&lt;/P&gt;&lt;P&gt;b) usually standard windows dialogs support &amp;lt;ESC&amp;gt; for aborting a dialog (IDCANCEL) and &amp;lt;Enter&amp;gt; for the OK-button (IDOK)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 13:51:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9479882#M6805</guid>
      <dc:creator>istan</dc:creator>
      <dc:date>2020-04-29T13:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: MXS: CreateDialog Enter/Escape Button</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480523#M6806</link>
      <description>&lt;P&gt;Can you put a [OK/Cancel] button in your modal dialog and set the focus to it? When the dialog appears the user has to press Enter and the on btn_Cancel do event will close the dialog.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works on max 2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;global rol_modal
try(destroyDialog rol_modal)catch()
rollout rol_modal "miauu"
(
label lbl_01 "Press Escape to close the dialog"
)
createdialog rol_modal modal:true escapeEnable:false&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 18:11:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480523#M6806</guid>
      <dc:creator>miauuuu</dc:creator>
      <dc:date>2020-04-29T18:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: MXS: CreateDialog Enter/Escape Button</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480628#M6807</link>
      <description>&lt;P&gt;do something with on-the-fly .net assembly and timer:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;fn createKeyboardAssembly =
(
	source = ""
	source += "using System;\n"
	source += "using System.Runtime.InteropServices;\n"
	source += "public class VirtualKeys\n"
	source += "{\n"
	source += "    const int VK_ESCAPE = 0x1B;\n"
	source += "    const int VK_RETURN = 0x0D;\n"
	source += "    const int KEY_PRESSED = 0x80;\n"
	source += "    [DllImport(\"user32.dll\", CharSet = CharSet.Auto, ExactSpelling = true)]\n"
	source += "    static extern short GetKeyState(int virtualKeyCode);\n"
	source += "    public bool IsEscapePressed() { return (GetKeyState(VK_ESCAPE) &amp;amp; KEY_PRESSED) == KEY_PRESSED; }\n"
	source += "    public bool IsReturnPressed() { return (GetKeyState(VK_RETURN) &amp;amp; KEY_PRESSED) == KEY_PRESSED; }\n"
	source += "}\n"

	csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"

	compilerParams.ReferencedAssemblies.Add("System.dll");

	compilerParams.GenerateInMemory = true
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)

	compilerResults.CompiledAssembly
)


try(destroydialog warning_dialog) catch()
rollout warning_dialog "Warning" width:191
(
	local vk_assembly = createKeyboardAssembly()
	local vk = vk_assembly.CreateInstance "VirtualKeys"
	
	local result = #default

	label text_lb "Press ESC or ENTER..." align:#left
		
	timer quit_timer interval:10
	on quit_timer tick do
	(
		case of
		(
			(vk.IsEscapePressed()):
			(
				result = #escape
				destroydialog warning_dialog
			)
			(vk.IsReturnPressed()):
			(
				result = #ok
				destroydialog warning_dialog
			)
		)
	)
		
	on warning_dialog close do
	(
		format "&amp;gt;&amp;gt; closed with %\n" result
	)
	on warning_dialog open do
	(
	)
)
createdialog warning_dialog modal:on escapeEnable:off&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 18:44:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480628#M6807</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2020-04-29T18:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: MXS: CreateDialog Enter/Escape Button</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480667#M6808</link>
      <description>&lt;P&gt;or make it more universal:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;fn createKeyboardAssembly =
(
	source = ""
	source += "using System;\n"
	source += "using System.Runtime.InteropServices;\n"
	source += "public class VirtualKeys\n"
	source += "{\n"
	source += "    const int KEY_PRESSED = 0x80;\n"
	source += "    [DllImport(\"user32.dll\", CharSet = CharSet.Auto, ExactSpelling = true)]\n"
	source += "    static extern short GetKeyState(int virtualKeyCode);\n"
	source += "    public bool IsKeyPressed(int key) { return (GetKeyState(key) &amp;amp; KEY_PRESSED) == KEY_PRESSED; }\n"
	source += "}\n"

	csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"

	compilerParams.ReferencedAssemblies.Add("System.dll");

	compilerParams.GenerateInMemory = true
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)

	compilerResults.CompiledAssembly
)

try(destroydialog warning_dialog) catch()
rollout warning_dialog "Warning" width:191
(
	local VK_ESCAPE = 0x1B
	local VK_RETURN = 0x0D
	local VK_SPACE  = 0x20

	local vk_assembly = createKeyboardAssembly()
	local vk = vk_assembly.CreateInstance "VirtualKeys"
	
	local result = #default

	label text_lb "Press ESC or ENTER..." align:#left
		
	timer quit_timer interval:10
	on quit_timer tick do
	(
		case of
		(
			(vk.IsKeyPressed(VK_ESCAPE)):
			(
				result = #escape
				destroydialog warning_dialog
			)
			(vk.IsKeyPressed(VK_RETURN)):
			(
				result = #ok
				destroydialog warning_dialog
			)
			(vk.IsKeyPressed(VK_SPACE)):
			(
				result = #space
				destroydialog warning_dialog
			)
		)
	)
		
	on warning_dialog close do
	(
		format "&amp;gt;&amp;gt; closed with %\n" result
	)
	on warning_dialog open do
	(
	)
)
createdialog warning_dialog modal:on escapeEnable:off&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 29 Apr 2020 18:55:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480667#M6808</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2020-04-29T18:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: MXS: CreateDialog Enter/Escape Button</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480922#M6809</link>
      <description>&lt;P&gt;I hoped it would be more simple &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; Nevertheless thx for the example!!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 20:51:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480922#M6809</guid>
      <dc:creator>istan</dc:creator>
      <dc:date>2020-04-29T20:51:48Z</dc:date>
    </item>
    <item>
      <title>Re: MXS: CreateDialog Enter/Escape Button</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480934#M6810</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1282940"&gt;@miauuuu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Can you put a [OK/Cancel] button in your modal dialog and set the focus to it? When the dialog appears the user has to press Enter and the on btn_Cancel do event will close the dialog.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Nice try, but this idea fails, as soon as you have a text field in the dialog, which has the focus.. The ok and cancel buttons have to work independantly of any other currently focussed control..&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2020 20:56:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/mxs-createdialog-enter-escape-button/m-p/9480934#M6810</guid>
      <dc:creator>istan</dc:creator>
      <dc:date>2020-04-29T20:56:20Z</dc:date>
    </item>
  </channel>
</rss>

