Dialog box selections using keyboard.

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9450
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Dialog box selections using keyboard.

Post by richmond62 » Sun Mar 12, 2023 10:17 am

Thanks, Bernd:

1. You ARE 'the man'.

2. I was being sleepy as I had already worked
out about traversal 2 weeks ago. :oops:

3. No need to use focus at all, now just using
textColor to know where to send a mouseUp
message.

Will post that code when back from church.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9450
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Dialog box selections using keyboard.

Post by richmond62 » Sun Mar 12, 2023 5:11 pm

What I wrote about textColor (while being possible) is not the method I used,
but my state of mind then was determined by

"Will post that code when back from church."

As went to church to bury a friend, and I was a bit . . .

The way to understand how I did things is to understand the context of my building a keyboard
to allow severely disabled people to type into a text field using ONLY these keys, or a subset of them:
-
keyBoardRestrictions.png
-
These can be easily mapped to a joystick, or for that matter a mouth-controlled device.

As you will see from the screen shot, my virtual keyboard is NOT complete, and needs further modification:
-
SShot 2023-03-12 at 18.09.55.png
-
This is the cardScript in the virtual keyboard palette:

Code: Select all

on openStack
   set the textColor of btn "b1" to blue
   put "1" into fld "kee"
   --focus on btn "b1"
end openStack

on arrowKey AK
   if AK = "right" then
      put fld "kee" into KEEE
      if exists(btn ("b" & KEEE)) then
         set the textColor of btn ("b" & KEEE) to red
         end if
         add 1 to KEEE
         put KEEE into fld "kee"
         if exists(btn ("b" & KEEE)) then
            set the textColor of btn ("b" & KEEE) to blue
            --focus on btn ("b" & KEEE)
         end if
      end if
      if AK = "left" then
         put fld "kee" into KEEE
         if exists(btn ("b" & KEEE)) then
            set the textColor of btn ("b" & KEEE) to red
         end if
         subtract 1 from KEEE
         put KEEE into fld "kee"
         if exists(btn ("b" & KEEE)) then
            set the textColor of btn ("b" & KEEE) to blue
            --focus on btn ("b" & KEEE)
         end if
      end if
   end arrowKey

on enterKey
   put fld "kee" into KEEY
   if exists(btn ("b" & KEEY)) then
      send "mouseUp" to btn ("b" & KEEY)
      end if
   end enterKey

on closeStack
   put 1 into Kred
   repeat until Kred > 35
      set the textColor of btn ("b" & Kred) to red
      add 1 to Kred
   end repeat
end closeStack
Last edited by richmond62 on Sun Mar 12, 2023 7:53 pm, edited 1 time in total.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9450
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Dialog box selections using keyboard.

Post by richmond62 » Sun Mar 12, 2023 5:24 pm

Mind you, this is a load of old cobblers:
-
SShot 2023-03-12 at 18.23.13.png
-
as I was expecting the cursor to move BACK one character . . .

. . . instead of a SPACE and a 'q'. :shock:

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9450
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Dialog box selections using keyboard.

Post by richmond62 » Sun Mar 12, 2023 5:41 pm

I would also like to know whether it is possible to show an insertion point in a field which has FOCUS turned OFF.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9747
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Dialog box selections using keyboard.

Post by dunbarx » Sun Mar 12, 2023 11:40 pm

Richmond.

Assuming you mean simply that if the field currently does not have focus, then I believe LC will automatically give it focus if you want a blinking cursor.

Craig
Last edited by dunbarx on Sun Mar 12, 2023 11:42 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9747
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Dialog box selections using keyboard.

Post by dunbarx » Sun Mar 12, 2023 11:42 pm

Interestingly, if one has a card with a button and a field, with the field NOT in focus, and this in the button script:

Code: Select all

on mouseUp
   select after text of fld 1
end mouseUp
The field becomes focussed with a blinking cursor. But if the same line of code is executed from the message box, nothing happens.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7258
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Dialog box selections using keyboard.

Post by jacque » Sun Mar 12, 2023 11:52 pm

If traversalOn is false then the field will not have a cursor, and apparently doesn't have a selection either, at least from the message box. This fails:

Code: Select all

put "abcde" into fld 1
select after char 2 of fld 1
put the selectedChunk
The response will refer to the message box. I imagine it will be the same from any handler. Is there a reason to turn off traversalOn?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9450
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Dialog box selections using keyboard.

Post by richmond62 » Mon Mar 13, 2023 10:05 am

The field, which is on a card on a different stack to the virtual keyboard, is blocked from receiving focus as it is part of what I hope will eventually be a joystick-controlled interface for LC/OXT to allow seriously disabled people to write computer programs.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9450
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Dialog box selections using keyboard.

Post by richmond62 » Mon Mar 13, 2023 12:09 pm

Here's another jolly problem:
-
Screen Shot 2023-03-13 at 1.06.41 pm.png
-

Code: Select all

on mouseUp
   put fld "nCHX" into CHX
   if exists(char (CHX + 1) in fld "ff") then
   select after char (CHX + 1) in fld "ff"
   put (CHX + 1) into fld "nCHX"
   end if
end mouseUp
Why is my right arrow key going on adding to fld "nCHX" when
there are only 11 characters in fld "ff"?
Attachments
Arrow key faker.livecode.zip
Stack.
(1.17 KiB) Downloaded 54 times

Cairoo
Posts: 107
Joined: Wed Dec 05, 2012 5:54 pm

Re: Dialog box selections using keyboard.

Post by Cairoo » Mon Mar 13, 2023 1:08 pm

richmond62 wrote:
Mon Mar 13, 2023 12:09 pm
Why is my right arrow key going on adding to fld "nCHX" when
there are only 11 characters in fld "ff"?
According to the dictionary, the exists function always returns true when specifying a chunk of a container. Perhaps you should simply test if the chunk is empty.

Gerrie

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4021
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Dialog box selections using keyboard.

Post by bn » Mon Mar 13, 2023 1:26 pm

Here is my take on button Bleft:

Code: Select all

on mouseUp
   put fld "nCHX" into CHX
   put the number of chars of field "ff" into tNumChars
   if CHX = 0 then
      beep
   end if
   if CHX > 0 and CHX <= tNumChars then
      select after char (CHX - 1) in fld "ff"
      put min(max(tNumChars,0),CHX-1) into field "nCHX"
   end if
end mouseUp
And here for button Bright

Code: Select all

on mouseUp
   put fld "nCHX" into CHX
   put the number of chars of field "ff" into tNumChars
   if CHX = tNumChars then
      beep
   end if
   if CHX >= 0 and CHX <= tNumChars then
      select after char (CHX + 1) in fld "ff"
      put min(max(tNumChars,0),CHX+1) into field "nCHX"
   end if
end mouseUp
Your use of "exist" in this context is new to me

Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9450
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Dialog box selections using keyboard.

Post by richmond62 » Tue Mar 14, 2023 12:40 pm

Thank you, Bernd: I was obviously being too clever with exists. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9450
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Dialog box selections using keyboard.

Post by richmond62 » Tue Mar 14, 2023 2:11 pm

Screen Shot 2023-03-14 at 3.10.25 pm.png
-
Attachments
Arrow key faker.livecode.zip
Stack.
(1.4 KiB) Downloaded 57 times

stam
Posts: 2744
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Dialog box selections using keyboard.

Post by stam » Fri Apr 14, 2023 12:26 pm

domzduzt wrote:
Fri Apr 14, 2023 11:19 am
I downloaded the revised stack. I can't figure how I could use this - no access to the coding for the selection buttons...
The code is in the button and card script - but. not sure what you actually mean.

On a related note, the 'forward delete' button does not work as one would imagine - it just goes to the end of line.

I'm not are what the use-case for this 'functionality' would be other than idle curiosity (I mean most would probably just use the actual arrow, delete and forward-delete keyboard keys) - perhaps if you let us know what it is you're trying to do?

S

Klaus
Posts: 13865
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Dialog box selections using keyboard.

Post by Klaus » Fri Apr 14, 2023 12:58 pm

Hi Stam,

I keep an eye on this possible spammer! ;-)


Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”