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

SparkOut
Posts: 2854
Joined: Sun Sep 23, 2007 4:58 pm

Re: give user keyboard option instead of clicking

Post by SparkOut » Tue Jul 18, 2023 7:23 am

Are you on Windows or Mac or Linux? The traversalOn property gives a bit different behaviour on each, according to the O/S provider's standards. On Windows a button with traversalOn set to true will be highlighted when navigating the page by the tab key and will be "pressed" if the user hits the spacebar while it has highlight. I believe Linux does something somewhat similar, but not sure. I don't think Mac behaves the same.
Best to try to make sure your application behaves in the way users of the platform expect.

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 » Tue Jul 18, 2023 4:43 pm

Most web pages use the tab-enter shortcut too. That's what I was thinking about when I asked to see the screenshot. Macs can be set up to behave the same way but it isn't the default so most users don't do it.

If traversalOn is set on the buttons then that may be all that's required. It may need a short script or behavior to catch the enter key, I can't remember. But it would work on Windows, and Mac users wouldn't know the difference.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: give user keyboard option instead of clicking

Post by CAsba » Wed Jul 19, 2023 2:33 pm

Hi all,
Sorry to say I couldn't get the screenshot to work, yeah, I know, basic stuff - but not something I do often, And I followed the instructions found on Google, but without success. Sorry again - for not being able to run the download richmond62 kindly offered; there is an aberration on my computer that insists I open livecode stuff using version 9.6.9. which has been removed from my computer, as it was causing me other problems and I'm using v.10. So I feel my hands are somewhat tied !
The optionkeydown method looked useful; I tried incorporating the script
answer question "You selected " & fld "cat1" & ". Is this correct?" with "NO" or "YES" titled field "fieldboxtitle" of cd "template1"

if it is "NO" then
answer "Try again. Click on the correct department."titled field "fieldboxtitle" of cd "template1"
exit optionKeyDown theKey
end if

if it is "YES" then
put "cat1" into fld "dept" of cd "doc2"
send "mouseup" to btn "ChangeDescription"
end if
#send "Mouseup" to btn "copytodoc2" of cd "manage products"
#end mouseup

answer numToChar(charToNum(theKey) - 1)
end optionKeyDown
but it failed to work - I was guessing how to do it as I couldn't find anything else on the web.
Can anyone put me on the right path here?
Oh, I took on board "you SHOULD use the mouse at the end of a process" - actually, the juncture is NOT the end, just another step along the way !

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

Re: give user keyboard option instead of clicking

Post by Klaus » Wed Jul 19, 2023 2:58 pm

The first line if missing from your script.
But please be a BIT more precise, "it failed to work" is a lousy error description! :-D
So what does not work, the complete script or what?

P.S.
Do not use the QUOTE tags after pasting your script(s) here, use the CODE tags, which looks like this: <>

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 19, 2023 5:40 pm

CAsba.

You have two parameters, "tKey" and "theKey" and I bet that is what is giving you a problem.

Anyway, I mocked up your handler with a card with some controls on it, substituting for the ones you had. All worked just fine.

Do put your handler into the "Code" tags "</>" not as a "quote". And do include the entire handler if possible.

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 » Wed Jul 19, 2023 5:43 pm

CAsba

Looking over your handler again, know that you do not need to:

Code: Select all

exit optionKeyDown theKey 
The "theKey" is ignored. You are simply exiting the "optionKey" handler itself; its parameters are not pertinent.

And because of this, the point I made about two different parameters in my earlier post is also not pertinent, for the same reason. Your handler runs fine, assuming the destination controls that you referenced exist correctly.

Craig

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

Re: give user keyboard option instead of clicking

Post by CAsba » Thu Jul 20, 2023 10:42 am

The missing first line is
[/code]on optionKeyDown theKey[/quote]
It failed inasmuch as neither Alt-1 nor Alt-K failed to activate the button.
I have to confess that I don't have much of a clue as to how to proceed with this coding, and the oncepts referred to in some of the comments are way beyond my understanding (which is why I identify as a complete beginner!)

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

Re: give user keyboard option instead of clicking

Post by Klaus » Thu Jul 20, 2023 11:08 am

Hi CAsba,

just made a test on my Mac, and yes the "optionkeydown" message does NOT get sent!?
However "comandkeydown" works fine, maybe you can use that one?

Code: Select all

on commandKeyDown tKey
   
   ## If you do not check the pressed key, then the handler does not make sense...
   if tKey <> "1" then
      ## This line will leave the handler immediately:
      pass commandkeydown
   end if
   answer question "You selected " & fld "cat1" & ". Is this correct?" with "NO" or "YES" titled field "fieldboxtitle" of cd "template1"
   
   if it is "NO" then
      answer "Try again. Click on the correct department."titled field "fieldboxtitle" of cd "template1" 
      exit commandKeyDown 
   end if
   
   ## No need for another IF THEN, since there is REALLY NO other option! :-)
   put "cat1" into fld "dept" of cd "doc2"
   send "mouseup" to btn "ChangeDescription"   
   answer numToChar(charToNum(theKey) - 1)
end commandKeyDown
Some hints:
1. This handler needs to be in the card script of the card with the buttons.
2. You should also actually check theKey! :-)
3. If the button "ChangeDescription" contains more than one line of script, you should "outsource" the handler to the card or stackscript!
Example in card script:

Code: Select all

command buttonclicked_shortcut_pressed
   ## do this
  ## and that
  ## and that over there also
  ## ...
end buttonclicked_shortcut_pressed
Then in the button/commandkeydown handler justexecute that handler:

Code: Select all

on mouseup
    buttonclicked_shortcut_pressed
end mouseup 

Code: Select all

on commandKeyDown tKey
   buttonclicked_shortcut_pressed
end commandKeyDown
Capisce?


Best

Klaus

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 » Thu Jul 20, 2023 2:01 pm

Klaus, CAsba.

The optionKey combination works fine for me. In fact, I always shy away from using the commandKey for this sort of shenanigans since that key is used so ubiquitously elsewhere.

I simply added the missing first line (it was obvious what it was) and, instead of making the distant control destinations that Casba's handler referenced, made a few local controls and substituted them in the handler itself. But doing that would neither have fixed nor broken the underlying flow of the code.

Craig

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

Re: give user keyboard option instead of clicking

Post by Klaus » Thu Jul 20, 2023 3:33 pm

dunbarx wrote:
Thu Jul 20, 2023 2:01 pm
...
The optionKey combination works fine for me.
...
does not work here! :(
What platform are you on, Mac or Windows?

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 » Thu Jul 20, 2023 4:42 pm

@Klaus.

What platform?? You cut me to the quick. It's the one with the bite taken out of it. :roll:

I made a new stack with a field named "cat1" and a button named "ChangeDescription". I did not feel like making and naming new cards. This in the card script:

Code: Select all

on optionKeyDown tkey
   
   answer question "You selected " & fld "cat1" & ". Is this correct?" with "NO" or "YES" --titled field "fieldboxtitle" of cd "template1"
   
   if it is "NO" then
     answer "Try again. Click on the correct department."titled field "fieldboxtitle" of cd "template1" 
     exit optionKeyDown theKey 
   end if
   
   if it is "YES" then 
      put "cat1" into fld  1 --"dept" of cd "doc2"
      send "mouseup" to btn "ChangeDescription"
   end if
   #send "Mouseup" to btn "copytodoc2" of cd "manage products"
   #end mouseup
   
   answer numToChar(charToNum(tKey) - 1)
end optionKeyDown
There is nothing in button "ChangeDescription". But who cares? I get a result from the final answer command. This means that the handler works. I assume that there are issues with the controls referenced with CAsba's setup.

@CAsba

If you place a breakpoint right after the last "answer" line does your handler stop at that point? If so, you have issues as I mentioned. If not, step through the entire handler and report back where LC throws an error.

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 » Thu Jul 20, 2023 4:46 pm

CAsba.

Going back to a point Klaus mentioned. You have to see that saying your "handler does not work" is virtually worthless for us. If you read and understand the two small tasks I gave you in the post just above, you should see that this is much more helpful.

For all of us. :wink:

Craig

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

Re: give user keyboard option instead of clicking

Post by Klaus » Thu Jul 20, 2023 5:32 pm

Too funky, tested again today with:

Code: Select all

on optionkeydown tKey
   answer tKey
end optionkeydown
and now it works...

Anyway completely forgot that pressing the option key will result in another character than exspected! :-D

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 » Thu Jul 20, 2023 5:56 pm

Klaus.

What? How could something not work and then work?? Or even the other way around???

CAsba. So this is now up to you. Your problem is not with your code, it is with something that you are doing elsewhere, likely all about those control references I am on about.

Craig

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

Re: give user keyboard option instead of clicking

Post by Klaus » Thu Jul 20, 2023 6:08 pm

dunbarx wrote:
Thu Jul 20, 2023 5:56 pm
Klaus.

What? How could something not work and then work?? Or even the other way around???
...
I bet the problem yesterday was sitting in front of my monitor! 8)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”