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