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

CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Dialog box selections using keyboard.

Post by CAsba » Mon Feb 13, 2023 1:32 pm

Hi,
Is there a (reasonably easy) way to let the user use the keyboard, arrows or tab, to move to another option in the dialog box?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Dialog box selections using keyboard.

Post by richmond62 » Mon Feb 13, 2023 2:00 pm

Can't see you managing that with this:
-
Screen Shot 2023-02-13 at 2.59.22 pm.png

CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Re: Dialog box selections using keyboard.

Post by CAsba » Mon Feb 13, 2023 2:24 pm

Hi,
Thanks for that, you probably saved me a lot of time trying; good to get your experienced opinion.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Dialog box selections using keyboard.

Post by dunbarx » Mon Feb 13, 2023 3:13 pm

CAsba

Dialog boxes like "Ask" and "Answer" block all but a very few actions, particular to each. Clicking one of the presented buttons (or using "Enter" or "Return" to select the default), along with the ability to enter text in an "ask" dialog is all she wrote.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Dialog box selections using keyboard.

Post by richmond62 » Mon Feb 13, 2023 3:24 pm

mouse.jpeg
-
It's a mouse-driven age. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Dialog box selections using keyboard.

Post by richmond62 » Tue Feb 14, 2023 9:49 am

Let's have slightly dubious fun setting up a substack as a dialog thingy:
-
Screen Shot 2023-02-14 at 10.47.48 am.png
-
set the traversalOn of ALL the buttons to true.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Dialog box selections using keyboard.

Post by richmond62 » Tue Feb 14, 2023 10:03 am

Here's a fake dialog palette:
-
Screen Shot 2023-02-14 at 11.00.42 am.png
-
You can use the RIGHT ARROW key to change the selected button.

You can use the ENTER (not the 'Return' key) to activate the selected button.

Code: Select all

on openStack
   focus on btn "B1"
   set the textColor of btn "B1" to red
end openStack

on enterKey
   send "mouseUp" to the focusedObject
end enterKey

on arrowKey AK
   if AK = "right" then
      if the textColor of btn "B3" is red then
         focus on btn "B1"
          set the textColor of btn "B3" to black
          set the textColor of btn "B1" to red
          end if
      if the textColor of btn "B2" is red then
         focus on btn "B3"
          set the textColor of btn "B2" to black
          set the textColor of btn "B3" to red
          end if
      if the textColor of btn "B1" is red then
         focus on btn "B2"
          set the textColor of btn "B1" to black
          set the textColor of btn "B2" to red
       end if
       end if
    end arrowKey
    
    on closeStack
       set the textColor of btn "B1" to black
       set the textColor of btn "B2" to black
       set the textColor of btn "B3" to black
    end closeStack
The reason I change the button text to red is because LiveCode gives NO visual cue (bad) when a button
receives focus.
Attachments
KB - DIALOGUE.livecode.zip
Stack.
(1.25 KiB) Downloaded 107 times

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7390
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Dialog box selections using keyboard.

Post by jacque » Tue Feb 14, 2023 6:34 pm

CAsba wrote:
Mon Feb 13, 2023 1:32 pm
Hi,
Is there a (reasonably easy) way to let the user use the keyboard, arrows or tab, to move to another option in the dialog box?
It's a system setting. As long as all controls have traversalOn set to true, it's automatic on Windows (and those users expect it.) On Mac the user can turn on the setting in system prefs. If they haven't done that it's probably better to leave things alone since they will be used to clicking dialog options.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Dialog box selections using keyboard.

Post by richmond62 » Wed Feb 15, 2023 12:08 pm

I did it my way.

AND it works.

SO, you have to decide whether to stick to some vague
orthopraxis, or break out and get the functionality you require.

CAsba
Posts: 431
Joined: Fri Sep 30, 2022 12:11 pm

Re: Dialog box selections using keyboard.

Post by CAsba » Wed Feb 15, 2023 5:11 pm

Thanks for that..
I did it this way...

Code: Select all

 answer question "You have entered the business name as:- " & CRLF & CRLF &\
               field "compnamex" of card "template1" & CRLF & CRLF &\ 
               "Is this correct?"  with "YES" or "NO"
         set the traversalon of btn "YES" to true 
         set the traversalon of btn "NO" to true 
         put it into field "fieldcr" of card "template1"
and it allows the user to tab to change selection.
Now I've got to dream up a way to inform the user of this facility...

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Dialog box selections using keyboard.

Post by Klaus » Wed Feb 15, 2023 5:23 pm

You can save some typing! :-)
Internally LC ALWAYS uses CR as a line delimiter!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Dialog box selections using keyboard.

Post by dunbarx » Wed Feb 15, 2023 5:37 pm

What Richmond did is fine because he rolled his own dialog box. That is just another LC gadget.

But for a minute I thought that CAsba had made that handler

Code: Select all

 answer question "You have entered the business name as:- " & CRLF & CRLF &\
               field "compnamex" of card "template1" & CRLF & CRLF &\ 
               "Is this correct?"  with "YES" or "NO"
         set the traversalon of btn "YES" to true 
         set the traversalon of btn "NO" to true 
         put it into field "fieldcr" of card "template1"
work on a "standard" answer dialog, that he was able to access the "Yes" and "No" buttons on the dialog itself. No way, and I do not want anyone else to think such a thing is possible.

Craig

Klaus
Posts: 14190
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Dialog box selections using keyboard.

Post by Klaus » Wed Feb 15, 2023 6:08 pm

Yes Craig and then these two lines are completely meaningless:

Code: Select all

set the traversalon of btn "YES" to true 
set the traversalon of btn "NO" to true 
Even if put BEFORE the "answer..." dialog!

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Dialog box selections using keyboard.

Post by richmond62 » Wed Feb 15, 2023 7:22 pm

You either do it 'my way', or you do it 'his way' ( Atkinson, MetaCard, Miller), but do NOT mix-and-match, as it will only end in tears before bedtime.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Dialog box selections using keyboard.

Post by dunbarx » Wed Feb 15, 2023 8:07 pm

Klaus.

That is actually what threw me. The original intent was to be able to "work" the buttons that are presented in a standard dialog box. I asserted that was not possible, that they were unavailable for access apart from a limited number of allowed user actions, like clicking on them. But not to select one of their presented buttons by, say, arrow key or tab key.

It is simple and satisfying to roll your own; have it your way. I do it now and then, and though always happy with the result, and no offense to anyone, I am rarely particularly proud of my efforts.

All I wanted to say was that modal dialog boxes are not accessible at all beyond the few actions they permit.

Craig

Post Reply