cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
Mauro_Gerber
Level IV

Set focus on text edit box

Hello

I try to check for an entry in a database with a barcode scanner.

It will enter the number and gives an enter at the end whitch triggers the script of the "text edit box".

What doesn't work is to reset the focus back on the box to enter the next number.

Names Default To Here( 1 );

dt = current data table();

try(win1<<close window;);

my_expr=expr(
	print(pnr << get text());
	pnr << settext("");
	pnr << 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),<<setscript(my_expr)),
		h list box(
			bb1 = Button Box( "Check",
				print(pnr << get text());
				pnr << settext("");
				//pnr  << setfocus();
			),
			bb2 = Button Box( "Cancel",
				win1 << close window;
			)
		)
	)
);
pnr << restore focus after click(1);  // does not work!

 

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS
1 ACCEPTED SOLUTION

Accepted Solutions
Mauro_Gerber
Level IV

Re: Set focus on text edit box

my current workaround with the help of https://community.jmp.com/t5/Discussions/JSL-to-input-an-Enter-keystroke/td-p/5872

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.

 

Names Default To Here( 1 );
clear log();

if(1==1,
	VK_TAB  = Hex to Number( "00000009" ); //&H9
	KEYEVENTF_EXTENDEDKEY = Hex to Number( "00000001" ); //&H1
	KEYEVENTTF_KEYDOWN = 0;
	KEYEVENTF_KEYUP = Hex to Number( "00000002" ); //&H2
	kernel32 = Load Dll( "kernel32" );
	kernel32 << DeclareFunction( "Sleep", Convention( STDCALL ), Alias( "Sleep" ),
		Arg( Int32, "dwMilliseconds" ),Returns( Void ) ); 
	user32 = Load Dll( "User32" );
	user32 << DeclareFunction( "FindWindowA", Convention( STDCALL ), Alias( "FindWindow2" ),
		Arg( UInt32, input, "lpClassName" ),Arg( AnsiString( 200 ), input, "lpCaption" ),Returns( UIntPtr )	);
	user32 << DeclareFunction( "SetForegroundWindow", Convention( STDCALL ), Alias( "SetForegroundWindow" ),
		Arg( UIntPtr, "hWnd" ),Returns( UInt32 ));
	user32 << DeclareFunction( "keybd_event", Convention( STDCALL ), Alias( "keybd_event" ),
        Arg( UInt8, "bVk" ),Arg( UInt8, "bScan" ),Arg( UInt32, "dwFlags" ),Arg( UIntPtr, "dwExtraInfo" ),Returns( Void )); 
	user32 << DeclareFunction( "GetKeyState", Convention( STDCALL ), Alias( "GetKeyState" ),
		Arg( Int32, "nVirtKey" ),Returns( Int32 ) ); 
	shell32 = Load Dll( "shell32" );
	shell32 << 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 << keybd_event( l_key, 0, 0, 0 );    // press key
				user32 << 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<<setfocus();
	wait(0.1);
	key( VK_TAB); 
);// code to set focus to the text edit box

try(win1<<close window;); // close windows when already open

my_expr=expr(
	item_nr = item << get text();
	item << 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),<<setscript(my_expr;reset_focus; ))),
		h list box(
			bb1 = Button Box( "Check",
				reset_focus;
			),
			bb9 = Button Box( "Cancel",
				win1 << close window;
				user32 << UnloadDll( );
				shell32 << UnloadDll( );
				kernel32 << UnloadDll( );
			)
		)
	)
);

mb << setkeyenable(1);
reset_focus;

 

 

Edit: The bb1 = Button Box( "Check",reset_focus;) seems to mess with the focus (sets it back to its self then to the next item).

 

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS

View solution in original post

5 REPLIES 5

Re: Set focus on text edit box

It appears that the << Set Focus and << Restore Focus After Click messages are not part of the protocol for a text edit box.

 

You can check for yourself by selecting Help > 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.

 

You can search for this message, for example, enter 'search' in the filter box. You won't find another object with this message.

 

You can also ask a display box object directly for its protocol:

Show Properties( Text Edit Box( "test" ) );
Mauro_Gerber
Level IV

Re: Set focus on text edit box

THX, I know, but that functionality is still missing.

I can use MouseBox and the SetKey function to at least reduce it to press TAB once to focus on the TextEditBox.

Names Default To Here( 1 );

dt = current data table();

try(win1<<close window;);

my_expr=expr(
	print(pnr << get text());
	pnr << settext("");
	//pnr << setfocus(); // does not work, error message!
	bb1 << 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),<<setscript(my_expr))),
		h list box(
			bb1 = Button Box( "Check",mb << setkeyenable(1); mb << setfocus,
				print(pnr << get text());
				pnr << settext("");
				//pnr  << setfocus();
			),
			bb2 = Button Box( "Cancel",
				win1 << close window;
			)
		)
	)
);
//pnr << restore focus after click(1);  // does not work!
mb << setkey( Function( {this, key}, {}, //no local variables
    pnr << settext( key );
    if(key =="ENTER", my_exp) ) );
mb << setkeyenable(1);
mb << setfocus;

It would be nice to set in the parameter of TextEditBox(...,...,...,next object when press TAB or ENTER).

In my case:

 

pnr = text edit box("example",set width(160),set nlines(1),<<setscript(my_expr),<<nextObj(pnr)) 

 

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS

Re: Set focus on text edit box

If you know about the omission, then what is your point?

 

Do you want a work-around? If so, then someone might be able to help you in this discussion.

 

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.

 

It is not clear what you want from this discussion.

Mauro_Gerber
Level IV

Re: Set focus on text edit box

Tank you for your reply and sorry for the unclear request.
I want to reset the focus on a TextEditBox.
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.
Wish List entry done --> https://community.jmp.com/t5/JMP-Wish-List/Set-next-focus-on-TextEditBox/idi-p/214995#M633
"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS
Mauro_Gerber
Level IV

Re: Set focus on text edit box

my current workaround with the help of https://community.jmp.com/t5/Discussions/JSL-to-input-an-Enter-keystroke/td-p/5872

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.

 

Names Default To Here( 1 );
clear log();

if(1==1,
	VK_TAB  = Hex to Number( "00000009" ); //&H9
	KEYEVENTF_EXTENDEDKEY = Hex to Number( "00000001" ); //&H1
	KEYEVENTTF_KEYDOWN = 0;
	KEYEVENTF_KEYUP = Hex to Number( "00000002" ); //&H2
	kernel32 = Load Dll( "kernel32" );
	kernel32 << DeclareFunction( "Sleep", Convention( STDCALL ), Alias( "Sleep" ),
		Arg( Int32, "dwMilliseconds" ),Returns( Void ) ); 
	user32 = Load Dll( "User32" );
	user32 << DeclareFunction( "FindWindowA", Convention( STDCALL ), Alias( "FindWindow2" ),
		Arg( UInt32, input, "lpClassName" ),Arg( AnsiString( 200 ), input, "lpCaption" ),Returns( UIntPtr )	);
	user32 << DeclareFunction( "SetForegroundWindow", Convention( STDCALL ), Alias( "SetForegroundWindow" ),
		Arg( UIntPtr, "hWnd" ),Returns( UInt32 ));
	user32 << DeclareFunction( "keybd_event", Convention( STDCALL ), Alias( "keybd_event" ),
        Arg( UInt8, "bVk" ),Arg( UInt8, "bScan" ),Arg( UInt32, "dwFlags" ),Arg( UIntPtr, "dwExtraInfo" ),Returns( Void )); 
	user32 << DeclareFunction( "GetKeyState", Convention( STDCALL ), Alias( "GetKeyState" ),
		Arg( Int32, "nVirtKey" ),Returns( Int32 ) ); 
	shell32 = Load Dll( "shell32" );
	shell32 << 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 << keybd_event( l_key, 0, 0, 0 );    // press key
				user32 << 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<<setfocus();
	wait(0.1);
	key( VK_TAB); 
);// code to set focus to the text edit box

try(win1<<close window;); // close windows when already open

my_expr=expr(
	item_nr = item << get text();
	item << 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),<<setscript(my_expr;reset_focus; ))),
		h list box(
			bb1 = Button Box( "Check",
				reset_focus;
			),
			bb9 = Button Box( "Cancel",
				win1 << close window;
				user32 << UnloadDll( );
				shell32 << UnloadDll( );
				kernel32 << UnloadDll( );
			)
		)
	)
);

mb << setkeyenable(1);
reset_focus;

 

 

Edit: The bb1 = Button Box( "Check",reset_focus;) seems to mess with the focus (sets it back to its self then to the next item).

 

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS