Page 4 of 4

Re: give user keyboard option instead of clicking

Posted: Tue Jul 25, 2023 6:36 pm
by dunbarx
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

Re: give user keyboard option instead of clicking

Posted: Tue Jul 25, 2023 6:40 pm
by dunbarx
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

Re: give user keyboard option instead of clicking

Posted: Tue Jul 25, 2023 7:13 pm
by richmond62
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]

Re: give user keyboard option instead of clicking

Posted: Tue Jul 25, 2023 10:34 pm
by dunbarx
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

Re: give user keyboard option instead of clicking

Posted: Wed Jul 26, 2023 12:20 am
by CAsba
Thanks, all, Ill try again tomorrow.
Nice phone...

Re: give user keyboard option instead of clicking

Posted: Wed Jul 26, 2023 1:58 pm
by CAsba
Gottit ! Everything works OK. Many thanks to all.

Re: give user keyboard option instead of clicking

Posted: Wed Jul 26, 2023 6:14 pm
by dunbarx
CAsba,

You are getting there. Keep at it...

Craig

Re: give user keyboard option instead of clicking

Posted: Wed Jul 26, 2023 6:27 pm
by jacque
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".

Re: give user keyboard option instead of clicking

Posted: Wed Jul 26, 2023 7:26 pm
by dunbarx
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

Re: give user keyboard option instead of clicking

Posted: Fri Nov 24, 2023 11:32 am
by CAsba
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 ?

Re: give user keyboard option instead of clicking

Posted: Fri Nov 24, 2023 5:36 pm
by dunbarx
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