Page 1 of 1

[SOLVED] Make the cursor move to next field ('select before text' not always working)

Posted: Wed Jun 26, 2019 8:21 pm
by redfield
Hi,
I have two fields and after a two-digit input in Field1 the cursor should move to Field2, without having to press tab or so. This is the script:

Code: Select all

on keyUp
   if length(me) = 2 then
      select before text of fld "Field2"
   end if
end keyUp
This works fine in the Linux standalone. But in the Windows standalone the cursor move only happens, if the two digits in Field1 are entered quite slowly. Meaning it depends on the input speed, if the cursor moves to Field2 or not. This seems a little strange. Is there a better way to script the desired cursor move?

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Wed Jun 26, 2019 10:15 pm
by richmond62
In terms of stacks (rather than standalones I made this:
-
Fshift.png
-
The code in fld "Field1" goes like this:

Code: Select all

on keyUp KP
   if length(me) > 1 then
      put empty into fld "Field2"
      select before fld "Field2"
   end if
end keyUp
I feel "a bit funny" about using keyUp without a variable after it.

I also feel that select before fld "Field2" is preferable to select before text of fld "Field2".

Whether this will make any difference in terms of functionality when
standalones are built has yet to be seen.

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Sun Jun 30, 2019 9:04 pm
by redfield
Many thanks for your suggestions. I tried them but unfortunately the problem remains: the cursor won't skip to the next field if the text in the first field is input too quickly - this though goes for the Windows standalone only. :?

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Mon Jul 01, 2019 9:08 am
by [-hh]
The following should work (close to that what you want).
It inputs at most two chars into fld 1, the keystroke for the third char selects the text of fld 2.
Contrary to your approach you can also edit fld 1.

Code: Select all

-- script of fld 1
on keyDown k
  if length(me) > 1 then
    select text of fld 2
    -- put k into fld 2 -- optional
  else pass keyDown
end keyDown

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Wed Jul 24, 2019 8:25 pm
by redfield
So I have tried all suggested scripts, but nothing changes. My original script is actually sufficient and does - on Linux - what I want it to do: skip the cursor to field 2 after entering two digits in field 1. On Windows this will only work if the two digits are not entered 'too fast'. Strangely though if I enter two same digits (e. g. 11 or 22), no matter how fast, the cursor will skip to the next field, as it is supposed to. Nothing tragic but noticeable as it perfectly works on Linux, no matter how fast or slow the digits are entered in a field.

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Wed Jul 24, 2019 8:55 pm
by bogs
Smells like a bug report should be filed.

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Wed Jul 24, 2019 9:36 pm
by [-hh]
@redfield.
My script (on keyDown) works here on Mac, Win and linux. Can only be disturbed by a "counteracting" keyUp.
Your script (on keyUp) may have problems because a "fast" keyDown comes before the pending actions from your last keyUp.

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Thu Jul 25, 2019 1:26 pm
by redfield
Hi -hh,
yes this code works fine (on Linux and Windows):

Code: Select all

-- script of fld 1
on keyDown k
  if length(me) > 1 then
    select text of fld 2
    -- put k into fld 2 -- optional
  else pass keyDown
end keyDown
Only that it's not exactly what I want. After having entered two digits, the user has to hit a key one more time, before the cursor skips. But I actually want the cursor to skip directly after the second digit has been entered. Which works perfectly fine with my original script, but again on Linux only (don't know about Mac, have none).

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Thu Jul 25, 2019 4:34 pm
by jacque
Try breaking it up into two handlers.

Code: Select all

-- script of fld 1
on keyDown k
  if length(me) < 2 then pass keyDown
end keyDown

on keyUp k
  if length(me) >= 2 then
    select text of fld 2
  end if 
 end keyUp

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Sun Jul 28, 2019 7:33 pm
by redfield
Have tried that too now, but unfortunately it doesn't change anything. The weird 'don't-type-too-fast' behaviour remains (on Windows). :(

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Sun Jul 28, 2019 7:55 pm
by FourthWorld
I wonder if the textChanged message may be more reliable in this context.

Re: Make the cursor move to next field ('select before text' not always working)

Posted: Mon Jul 29, 2019 8:22 pm
by redfield
In fact that works like a charme! The code is now:

Code: Select all

on textChanged
   if length(me) > 1 then
      select text of fld 2
   end if
end textChanged
Cursor is finally responding as it should to my racy typing skills, on both, Linux and Windows :D