give user keyboard option instead of clicking

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

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

Re: give user keyboard option instead of clicking

Post by dunbarx » Tue Jul 25, 2023 6:36 pm

Important to know that if one does not include a "break" command after each case statement, the handler will continue to subsequent case statements.

Craig

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

Re: give user keyboard option instead of clicking

Post by dunbarx » Tue Jul 25, 2023 6:40 pm

I cannot help but raise again a real long standing wish of mine, that the "Switch" control structure be enhanced as per:

https://forums.livecode.com/viewtopic.p ... itch+table

Craig

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

Re: give user keyboard option instead of clicking

Post by richmond62 » Tue Jul 25, 2023 7:13 pm

I am inclined to agree: the current Switch thing means that one gets kicked out of it IFF one condition is satisfied.

However, in the real world we all know that quite often more than 1 condition may be satisfied.

[Richmond is Scots AND he has red hair]

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

Re: give user keyboard option instead of clicking

Post by dunbarx » Tue Jul 25, 2023 10:34 pm

Richmond.

Many here would say, and not without good reason, that one could (pseudo):

Code: Select all

case Richmond is "Scots" and Richmond has red hair
We all do that.

My point is that with the "Continue" variant of "Switch", one does not have to think about the ordering of the several "Case" statements, so that they filter correctly according to the intent of the programmer. Since each acts independently on its own logical merits, the cases can be listed in any manner, and the end result will be the same.

Craig

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

Re: give user keyboard option instead of clicking

Post by CAsba » Wed Jul 26, 2023 12:20 am

Thanks, all, Ill try again tomorrow.
Nice phone...

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

Re: give user keyboard option instead of clicking

Post by CAsba » Wed Jul 26, 2023 1:58 pm

Gottit ! Everything works OK. Many thanks to all.

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

Re: give user keyboard option instead of clicking

Post by dunbarx » Wed Jul 26, 2023 6:14 pm

CAsba,

You are getting there. Keep at it...

Craig

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

Re: give user keyboard option instead of clicking

Post by jacque » Wed Jul 26, 2023 6:27 pm

dunbarx wrote:
Tue Jul 25, 2023 6:40 pm
I cannot help but raise again a real long standing wish of mine, that the "Switch" control structure be enhanced as per:

https://forums.livecode.com/viewtopic.p ... itch+table
That would be antithetical to all other programming languages which use switch similarly to LC. It's a very common control structure. But if you reorder your example and allow fallthrough between the first and third (now second) cases you could get "2".
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: give user keyboard option instead of clicking

Post by dunbarx » Wed Jul 26, 2023 7:26 pm

Jacque.

My point was that, and you were all over that earlier thread, using the "Continue" variant of "Switch" allowed much more functionality. Again, each "Case" statement would be evaluated on its own merits, regardless of the ordering of those cases, or whether or not an earlier case "fired" or not.

Certainly, like you and everyone else, I must think about the best ordering of the case statements in any given Switch control structure. This to make sure that the most "important" case gets "caught" before another, possibly pertinent, one does. But I must be satisfied with the first one, period.

Here is perhaps a better way for me to try to sell this:

With if-then, something like:

Code: Select all

if 1 = 1 then add 1 to accum
if 2 = 500 then add 1 to accum
if 3 = 3 then add 1 to accum
I get "2", as I wanted.

But I cannot:

Code: Select all

on mouseUp
   if 1 = 1 then add 1 to accum
   else if 2 = 500 then add 1 to accum
   else if 3 = 3 then add 1 to accum
end mouseUp
Now I get "1", because, just like with the current "Switch", the process exits after the first valid expression "fires".

See?

Anyway, I just thought that a new Switch variant would be really useful, because if-then, especially if a lot of nesting is required, is far less readable, and far less writable as well.

Craig
Last edited by dunbarx on Fri Nov 24, 2023 5:23 pm, edited 3 times in total.

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

Re: give user keyboard option instead of clicking

Post by CAsba » Fri Nov 24, 2023 11:32 am

Hi again,
I gleaned enough from the last time this post was current to use the folowing code, which works well:-

Code: Select all

on commandkeydown tKey
   switch tKey
      case "1"
         send "mouseup" to btn "help"
         break
      case "2"
         send "mouseup" to btn "tryout"
         break
      case "3"
         send "mouseup" to btn "tryout2"
         break
      case "4"
         send "mouseup" to btn "tryout3"
         break
      case "5"
         send "mouseup" to btn "tryout4"
         break
      case "6"
         send "mouseup" to btn "tryout5"
         break
      case "7"
         send "mouseup" to btn "tryout6"
         break
      case "f9"
         send "mouseup" to btn "Go back"
         break
   end switch
end commandkeydown
 
Now I need to explore the use of the Alt + key as I don't want to use Ctrl - letter keys which only leaves me 9 single digit numbers, and, therefore, options.

I tried using the code that Jacque kindly suggested, but I'm afraid it just gives a beep and doesn't work, it's:-

Code: Select all

on optionKeyDown pKey
   switch pKey
      case 1
         answer "33"
         #send "mouseUp" to btn 1
         break
      case 2
         answer "44"
         #send "mouseUp" to btn 2
         break
         -- etc.
   end switch
end optionKeyDown
 
Can anyone help please ?

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

Re: give user keyboard option instead of clicking

Post by dunbarx » Fri Nov 24, 2023 5:36 pm

CAsba.

Your issue is that the option key changes the keyboard. For example, opt-2 does not return "2", it returns "™".

Try to use another modifier key. Or better, learn the "option-changed" keyboard (your Mac has that as a menu gadget) and map them explicitly in your handler. For example, for "2":

Code: Select all

on optionKeyDown pKey
   switch pKey
      case "™"   --user presses "2"
         answer 2"
        --do "2" stuff here
       ....
The user will never see the "actual" returned character, and the process will proceed as you wanted.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”