<?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: Set focus on text edit box in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/215576#M43071</link>
    <description>&lt;P&gt;my current workaround with the help of &lt;A href="https://community.jmp.com/t5/Discussions/JSL-to-input-an-Enter-keystroke/td-p/5872" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/Discussions/JSL-to-input-an-Enter-keystroke/td-p/5872&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Its basicly the following: put a mouse box around the text edit box. Set focus on the mouse box and press TAB witch sets the focus on the text edit box.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
clear log();

if(1==1,
	VK_TAB  = Hex to Number( "00000009" ); //&amp;amp;H9
	KEYEVENTF_EXTENDEDKEY = Hex to Number( "00000001" ); //&amp;amp;H1
	KEYEVENTTF_KEYDOWN = 0;
	KEYEVENTF_KEYUP = Hex to Number( "00000002" ); //&amp;amp;H2
	kernel32 = Load Dll( "kernel32" );
	kernel32 &amp;lt;&amp;lt; DeclareFunction( "Sleep", Convention( STDCALL ), Alias( "Sleep" ),
		Arg( Int32, "dwMilliseconds" ),Returns( Void ) ); 
	user32 = Load Dll( "User32" );
	user32 &amp;lt;&amp;lt; DeclareFunction( "FindWindowA", Convention( STDCALL ), Alias( "FindWindow2" ),
		Arg( UInt32, input, "lpClassName" ),Arg( AnsiString( 200 ), input, "lpCaption" ),Returns( UIntPtr )	);
	user32 &amp;lt;&amp;lt; DeclareFunction( "SetForegroundWindow", Convention( STDCALL ), Alias( "SetForegroundWindow" ),
		Arg( UIntPtr, "hWnd" ),Returns( UInt32 ));
	user32 &amp;lt;&amp;lt; DeclareFunction( "keybd_event", Convention( STDCALL ), Alias( "keybd_event" ),
        Arg( UInt8, "bVk" ),Arg( UInt8, "bScan" ),Arg( UInt32, "dwFlags" ),Arg( UIntPtr, "dwExtraInfo" ),Returns( Void )); 
	user32 &amp;lt;&amp;lt; DeclareFunction( "GetKeyState", Convention( STDCALL ), Alias( "GetKeyState" ),
		Arg( Int32, "nVirtKey" ),Returns( Int32 ) ); 
	shell32 = Load Dll( "shell32" );
	shell32 &amp;lt;&amp;lt; DeclareFunction( "ShellExecuteA", Convention( STDCALL ),    Alias( "ShellExecute" ),
		Arg( UIntPtr, input, "hWnd" ),Arg( AnsiString( 20 ), "lpOperation" ),Arg( AnsiString( 256 ), "lpFile" ),
		Arg( AnsiString( 256 ), "lpParameters" ), /* Arg( UInt32, "lpParameters" ), */Arg( UInt32, "lpDirectory" ),
		Arg( UInt32, "nShowCmd" ),Returns( UInt32 ));
	key = function( { l_key },
				user32 &amp;lt;&amp;lt; keybd_event( l_key, 0, 0, 0 );    // press key
				user32 &amp;lt;&amp;lt; keybd_event( l_key, 0, KEYEVENTF_KEYUP, 0 );    // release key
	);  
); // Setup the win key command code from the JMP community: https://community.jmp.com/t5/Discussions/JSL-to-input-an-Enter-keystroke/td-p/5872

reset_focus = expr(
	wait(0.1);
	mb&amp;lt;&amp;lt;setfocus();
	wait(0.1);
	key( VK_TAB); 
);// code to set focus to the text edit box

try(win1&amp;lt;&amp;lt;close window;); // close windows when already open

my_expr=expr(
	item_nr = item &amp;lt;&amp;lt; get text();
	item &amp;lt;&amp;lt; settext("");
	
	print(item_nr);
	// execute code when item is entred
	
	reset_focus;
);


win1 = New Window( "Scan Window",
	V List Box(
		Text Box( "Scan Item" ),
		mb = mousebox(item = text edit box("",set width(160),set nlines(1),&amp;lt;&amp;lt;setscript(my_expr;reset_focus; ))),
		h list box(
			bb1 = Button Box( "Check",
				reset_focus;
			),
			bb9 = Button Box( "Cancel",
				win1 &amp;lt;&amp;lt; close window;
				user32 &amp;lt;&amp;lt; UnloadDll( );
				shell32 &amp;lt;&amp;lt; UnloadDll( );
				kernel32 &amp;lt;&amp;lt; UnloadDll( );
			)
		)
	)
);

mb &amp;lt;&amp;lt; setkeyenable(1);
reset_focus;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: The bb1 &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Button Box&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"Check"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;reset_focus&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;) seems to mess with the focus (sets it back to its self then to the next item).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jul 2019 09:59:34 GMT</pubDate>
    <dc:creator>Mauro_Gerber</dc:creator>
    <dc:date>2019-07-01T09:59:34Z</dc:date>
    <item>
      <title>Set focus on text edit box</title>
      <link>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214980#M42978</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I try to check for an entry in a database with a barcode scanner.&lt;/P&gt;&lt;P&gt;It will enter the number and gives an enter at the end whitch triggers the script of the "text edit box".&lt;/P&gt;&lt;P&gt;What doesn't work is to reset the focus back on the box to enter the next number.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = current data table();

try(win1&amp;lt;&amp;lt;close window;);

my_expr=expr(
	print(pnr &amp;lt;&amp;lt; get text());
	pnr &amp;lt;&amp;lt; settext("");
	pnr &amp;lt;&amp;lt; setfocus(); // does not work, error message!
);

win1 = New Window( "Scan Window",modal,
	V List Box(
		Text Box( "Scan Serialnumber" ),
		pnr = text edit box("",set width(160),set nlines(1),&amp;lt;&amp;lt;setscript(my_expr)),
		h list box(
			bb1 = Button Box( "Check",
				print(pnr &amp;lt;&amp;lt; get text());
				pnr &amp;lt;&amp;lt; settext("");
				//pnr  &amp;lt;&amp;lt; setfocus();
			),
			bb2 = Button Box( "Cancel",
				win1 &amp;lt;&amp;lt; close window;
			)
		)
	)
);
pnr &amp;lt;&amp;lt; restore focus after click(1);  // does not work!&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 11:04:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214980#M42978</guid>
      <dc:creator>Mauro_Gerber</dc:creator>
      <dc:date>2019-06-27T11:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Set focus on text edit box</title>
      <link>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214990#M42979</link>
      <description>&lt;P&gt;It appears that the &amp;lt;&amp;lt; Set Focus and &amp;lt;&amp;lt; Restore Focus After Click messages are not part of the protocol for a text edit box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can check for yourself by selecting Help &amp;gt; Scripting Index. Change the list to Display Box and then select the TextEditBox item. You won't find this message in the second list that shows the entire protocol.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can search for this message, for example, enter 'search' in the filter box. You won't find another object with this message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also ask a display box object directly for its protocol:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Show Properties( Text Edit Box( "test" ) );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:19:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214990#M42979</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2019-06-27T12:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Set focus on text edit box</title>
      <link>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214993#M42981</link>
      <description>&lt;P&gt;THX, I know, but that functionality is still missing.&lt;/P&gt;&lt;P&gt;I can use MouseBox and the SetKey function to at least reduce&amp;nbsp;it to press TAB once to focus on the TextEditBox.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = current data table();

try(win1&amp;lt;&amp;lt;close window;);

my_expr=expr(
	print(pnr &amp;lt;&amp;lt; get text());
	pnr &amp;lt;&amp;lt; settext("");
	//pnr &amp;lt;&amp;lt; setfocus(); // does not work, error message!
	bb1 &amp;lt;&amp;lt; click;
);

win1 = New Window( "Scan Window",modal,
	V List Box(
		Text Box( "Scan Serialnumber" ),
		mb = mousebox(pnr = text edit box("",set width(160),set nlines(1),&amp;lt;&amp;lt;setscript(my_expr))),
		h list box(
			bb1 = Button Box( "Check",mb &amp;lt;&amp;lt; setkeyenable(1); mb &amp;lt;&amp;lt; setfocus,
				print(pnr &amp;lt;&amp;lt; get text());
				pnr &amp;lt;&amp;lt; settext("");
				//pnr  &amp;lt;&amp;lt; setfocus();
			),
			bb2 = Button Box( "Cancel",
				win1 &amp;lt;&amp;lt; close window;
			)
		)
	)
);
//pnr &amp;lt;&amp;lt; restore focus after click(1);  // does not work!
mb &amp;lt;&amp;lt; setkey( Function( {this, key}, {}, //no local variables
    pnr &amp;lt;&amp;lt; settext( key );
    if(key =="ENTER", my_exp) ) );
mb &amp;lt;&amp;lt; setkeyenable(1);
mb &amp;lt;&amp;lt; setfocus;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It would be nice to set in the parameter of TextEditBox(...,...,...,next object when press TAB or ENTER).&lt;/P&gt;&lt;P&gt;In my case:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;pnr = text edit box("example",set width(160),set nlines(1),&amp;lt;&amp;lt;setscript(my_expr),&amp;lt;&amp;lt;nextObj(pnr))&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:05:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214993#M42981</guid>
      <dc:creator>Mauro_Gerber</dc:creator>
      <dc:date>2019-06-27T12:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Set focus on text edit box</title>
      <link>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214994#M42982</link>
      <description>&lt;P&gt;If you know about the omission, then what is your point?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want a work-around? If so, then someone might be able to help you in this discussion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want new functionality? If so, then go to the Wish List part of the JMP Community. Check to see if someone has already requested something like this need. If not, please add it for consideration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is not clear what you want from this discussion.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:24:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214994#M42982</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2019-06-27T12:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Set focus on text edit box</title>
      <link>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214996#M42983</link>
      <description>Tank you for your reply and sorry for the unclear request.&lt;BR /&gt;I want to reset the focus on a TextEditBox.&lt;BR /&gt;I don't know if there is a "hidden" function, I couldn't find a solution on the community pages so a work-around would be a solution.&lt;BR /&gt;Wish List entry done --&amp;gt; &lt;A href="https://community.jmp.com/t5/JMP-Wish-List/Set-next-focus-on-TextEditBox/idi-p/214995#M633" target="_blank"&gt;https://community.jmp.com/t5/JMP-Wish-List/Set-next-focus-on-TextEditBox/idi-p/214995#M633&lt;/A&gt;</description>
      <pubDate>Thu, 27 Jun 2019 12:52:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/214996#M42983</guid>
      <dc:creator>Mauro_Gerber</dc:creator>
      <dc:date>2019-06-27T12:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Set focus on text edit box</title>
      <link>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/215576#M43071</link>
      <description>&lt;P&gt;my current workaround with the help of &lt;A href="https://community.jmp.com/t5/Discussions/JSL-to-input-an-Enter-keystroke/td-p/5872" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/Discussions/JSL-to-input-an-Enter-keystroke/td-p/5872&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Its basicly the following: put a mouse box around the text edit box. Set focus on the mouse box and press TAB witch sets the focus on the text edit box.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
clear log();

if(1==1,
	VK_TAB  = Hex to Number( "00000009" ); //&amp;amp;H9
	KEYEVENTF_EXTENDEDKEY = Hex to Number( "00000001" ); //&amp;amp;H1
	KEYEVENTTF_KEYDOWN = 0;
	KEYEVENTF_KEYUP = Hex to Number( "00000002" ); //&amp;amp;H2
	kernel32 = Load Dll( "kernel32" );
	kernel32 &amp;lt;&amp;lt; DeclareFunction( "Sleep", Convention( STDCALL ), Alias( "Sleep" ),
		Arg( Int32, "dwMilliseconds" ),Returns( Void ) ); 
	user32 = Load Dll( "User32" );
	user32 &amp;lt;&amp;lt; DeclareFunction( "FindWindowA", Convention( STDCALL ), Alias( "FindWindow2" ),
		Arg( UInt32, input, "lpClassName" ),Arg( AnsiString( 200 ), input, "lpCaption" ),Returns( UIntPtr )	);
	user32 &amp;lt;&amp;lt; DeclareFunction( "SetForegroundWindow", Convention( STDCALL ), Alias( "SetForegroundWindow" ),
		Arg( UIntPtr, "hWnd" ),Returns( UInt32 ));
	user32 &amp;lt;&amp;lt; DeclareFunction( "keybd_event", Convention( STDCALL ), Alias( "keybd_event" ),
        Arg( UInt8, "bVk" ),Arg( UInt8, "bScan" ),Arg( UInt32, "dwFlags" ),Arg( UIntPtr, "dwExtraInfo" ),Returns( Void )); 
	user32 &amp;lt;&amp;lt; DeclareFunction( "GetKeyState", Convention( STDCALL ), Alias( "GetKeyState" ),
		Arg( Int32, "nVirtKey" ),Returns( Int32 ) ); 
	shell32 = Load Dll( "shell32" );
	shell32 &amp;lt;&amp;lt; DeclareFunction( "ShellExecuteA", Convention( STDCALL ),    Alias( "ShellExecute" ),
		Arg( UIntPtr, input, "hWnd" ),Arg( AnsiString( 20 ), "lpOperation" ),Arg( AnsiString( 256 ), "lpFile" ),
		Arg( AnsiString( 256 ), "lpParameters" ), /* Arg( UInt32, "lpParameters" ), */Arg( UInt32, "lpDirectory" ),
		Arg( UInt32, "nShowCmd" ),Returns( UInt32 ));
	key = function( { l_key },
				user32 &amp;lt;&amp;lt; keybd_event( l_key, 0, 0, 0 );    // press key
				user32 &amp;lt;&amp;lt; keybd_event( l_key, 0, KEYEVENTF_KEYUP, 0 );    // release key
	);  
); // Setup the win key command code from the JMP community: https://community.jmp.com/t5/Discussions/JSL-to-input-an-Enter-keystroke/td-p/5872

reset_focus = expr(
	wait(0.1);
	mb&amp;lt;&amp;lt;setfocus();
	wait(0.1);
	key( VK_TAB); 
);// code to set focus to the text edit box

try(win1&amp;lt;&amp;lt;close window;); // close windows when already open

my_expr=expr(
	item_nr = item &amp;lt;&amp;lt; get text();
	item &amp;lt;&amp;lt; settext("");
	
	print(item_nr);
	// execute code when item is entred
	
	reset_focus;
);


win1 = New Window( "Scan Window",
	V List Box(
		Text Box( "Scan Item" ),
		mb = mousebox(item = text edit box("",set width(160),set nlines(1),&amp;lt;&amp;lt;setscript(my_expr;reset_focus; ))),
		h list box(
			bb1 = Button Box( "Check",
				reset_focus;
			),
			bb9 = Button Box( "Cancel",
				win1 &amp;lt;&amp;lt; close window;
				user32 &amp;lt;&amp;lt; UnloadDll( );
				shell32 &amp;lt;&amp;lt; UnloadDll( );
				kernel32 &amp;lt;&amp;lt; UnloadDll( );
			)
		)
	)
);

mb &amp;lt;&amp;lt; setkeyenable(1);
reset_focus;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: The bb1 &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Button Box&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"Check"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;reset_focus&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;) seems to mess with the focus (sets it back to its self then to the next item).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 09:59:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Set-focus-on-text-edit-box/m-p/215576#M43071</guid>
      <dc:creator>Mauro_Gerber</dc:creator>
      <dc:date>2019-07-01T09:59:34Z</dc:date>
    </item>
  </channel>
</rss>

