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

Deploying to Windows? Utilizing VB Script execution? This is the place to ask Windows-specific questions.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
redfield
Posts: 95
Joined: Thu Apr 04, 2019 1:41 pm

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

Post 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?
Last edited by redfield on Mon Jul 29, 2019 8:25 pm, edited 1 time in total.
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10430
Joined: Fri Feb 19, 2010 10:17 am

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

Post 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.
Attachments
Field Shift.livecode.zip
Here's the stack.
(1.01 KiB) Downloaded 876 times
redfield
Posts: 95
Joined: Thu Apr 04, 2019 1:41 pm

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

Post 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. :?
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

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

Post 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
shiftLock happens
redfield
Posts: 95
Joined: Thu Apr 04, 2019 1:41 pm

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

Post 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.
bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

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

Post by bogs »

Smells like a bug report should be filed.
Image
[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

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

Post 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.
shiftLock happens
redfield
Posts: 95
Joined: Thu Apr 04, 2019 1:41 pm

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

Post 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).
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

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

Post 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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
redfield
Posts: 95
Joined: Thu Apr 04, 2019 1:41 pm

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

Post 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). :(
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10104
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld »

I wonder if the textChanged message may be more reliable in this context.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
redfield
Posts: 95
Joined: Thu Apr 04, 2019 1:41 pm

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

Post 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
Post Reply