give user keyboard option instead of clicking
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- 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
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
Craig
-
- 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
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
https://forums.livecode.com/viewtopic.p ... itch+table
Craig
-
- Livecode Opensource Backer
- Posts: 9417
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: give user keyboard option instead of clicking
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]
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]
-
- 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
Richmond.
Many here would say, and not without good reason, that one could (pseudo):
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
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
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
Thanks, all, Ill try again tomorrow.
Nice phone...
Nice phone...
Re: give user keyboard option instead of clicking
Gottit ! Everything works OK. Many thanks to all.
-
- 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
CAsba,
You are getting there. Keep at it...
Craig
You are getting there. Keep at it...
Craig
-
- 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
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".dunbarx wrote: ↑Tue Jul 25, 2023 6:40 pmI 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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- 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
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:
I get "2", as I wanted.
But I cannot:
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
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
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
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.
Re: give user keyboard option instead of clicking
Hi again,
I gleaned enough from the last time this post was current to use the folowing code, which works well:-
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:-
Can anyone help please ?
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
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
-
- 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
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":
The user will never see the "actual" returned character, and the process will proceed as you wanted.
Craig
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
....
Craig