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

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

give user keyboard option instead of clicking

Post by CAsba » Fri Jul 14, 2023 12:37 pm

Hi, My user will choose from six departments, each having a button. I would like to give the user the option of a keyboard combination for each btn. Version is 10. Any ideas ?

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 » Fri Jul 14, 2023 12:56 pm

Hi CAsba,

you could add a -> commandkeydown tKey
handler to the card script of the card with your buttons:

Code: Select all

on commandkeydown tKey
   switch tKey
      case "1"
         ## do your things here
         break
      case "2"
         ## etc.
         ## for all 6 options
         ...
or use the -> functionkey tKey command.
Usage like like the above example.

Best

Klaus

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 » Fri Jul 14, 2023 12:59 pm

You can also use arrow keys to highlight buttons, followed by the ENTER key.

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

Re: give user keyboard option instead of clicking

Post by CAsba » Fri Jul 14, 2023 1:14 pm

Hmm,
Not sure about this..There are many other buttons on the page, some shown, some hidden.
When I posed the question I had in mind a solution whereby, beneath each button would be a keyboard
combination, for example, alt -zz, or similar to activate the button. Would this be possible ?

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 » Fri Jul 14, 2023 1:19 pm

If you don't like the COMMAND key, use -> optionkeydown tKey 8)

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 » Fri Jul 14, 2023 1:28 pm

CAsba wrote:
Fri Jul 14, 2023 1:14 pm
Hmm,
Not sure about this..There are many other buttons on the page, some shown, some hidden.
When I posed the question I had in mind a solution whereby, beneath each button would be a keyboard
combination, for example, alt -zz, or similar to activate the button. Would this be possible ?
Also not sure about this!? :-D
A keyboard shortcut will do the same as clicking the button, so why on earth a shortcut to ACTIVATE
the button which still requires to hit ENTER or RETURN?
Or am I misunderstanding this?

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 » Fri Jul 14, 2023 2:30 pm

Yes, I think you are misunderstanding part of what is going on, as it is me you should be criticising about ENTER key usage not Casba.

Mind you, if he has LOTS of keys (some of which are HIDDEN) things get very queer indeed.

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 » Fri Jul 14, 2023 10:32 pm

CAsba wrote:
Fri Jul 14, 2023 1:14 pm
When I posed the question I had in mind a solution whereby, beneath each button would be a keyboard
combination, for example, alt -zz, or similar to activate the button. Would this be possible ?
As suggested, you can trap for the command/control key, the option/alt key, or the function keys. On Mac, most of the letters are already assigned to command-key actions by the OS (Cmd-S for save, Cmd-W for close, etc.) and I believe Windows is likewise crowded. Using the Option/Alt key or function keys would probably be better, but whatever you choose to use, try not to override the commonly expected behaviors.

It is harder to trap for more than one letter. It can be done but requires more scripting and setting up a timer to know if the user typed the second letter quickly enough after the first. It's much easier to use only a single letter with one of the modifier keys. You suggested Alt, which in LC is the option key, so this is what you'd do:

Code: Select all

on optionKeyDown pKey
  switch pKey
    case 1
      send "mouseUp" to btn 1
      break
    case 2
      send "mouseUp" to btn 2
      break
      -- etc.
  end switch
end optionKeyDown
I'm on a Mac here but I suspect Windows will have the same behavior: since the Option/Alt key is down when the handler runs, you will get the special option-key character rather than the name of the key you typed. You can change the switch cases to match those special keys (i.e. "case 1" would be "case ¡" on Mac.) The same is true for any non-numeric key press, you will get the special character rather than the one printed on the keyboard.

If you use the Command/Control modifier key instead, you do get the character that is printed on the keyboard. "Case 1" will recognize the number 1, or any other letter that is typed.

There is another way to do this. Write a rawKeyDown handler that checks for the character that was typed and also checks to see if the modifier key of your choice is also down at the same time.

Code: Select all

on rawKeyDown pKey
  if the optionKey is not down then pass rawKeyDown -- or commandKey or functionKey
  switch pKey
    case 1
      send "mouseUp" to btn 1
      break
    case 2
      send "mouseUp to btn 2"
      break
  end switch
end rawKeyDown
However, this has the same caveat as the first method. The raw key codes are numbers, so you need to substitute those. For example, the number 1 is rawKeyCode 49 on a Mac. If you put a breakpoint at the beginning of the switch statement, you can see which key codes correspond to the number or letter you are typing.

The short answer: use a modifier key and a switch statement to send a message to the button that should respond.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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 » Sat Jul 15, 2023 8:23 am

SShot 2023-07-15 at 10.22.55.png
-
Attachments
keyCoder.livecode.zip
Stack.
(9.87 KiB) Downloaded 78 times

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

Re: give user keyboard option instead of clicking

Post by CAsba » Mon Jul 17, 2023 3:26 pm

Hi all, thanks for all your comments.
May I reply to Klaus's comment ?
Yes I want the user to be able to use the keyboard as well as the mouse for activating one of six buttons, (which refer to 'departments' of the user's business). Prior to this decision the user has chosen 'Yes' to five Yes/No selections, and these could all be answered by using the keyboard - Enter. As it stands, the user must now stop using the keyboard, grab the mouse, and click on a button. I think it would be more consistently user-friendly if she could type in, say, Alt-9, ( or similar) that would be displayed under the button, and not break the continuity of using the keyboard. That's all.

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 » Mon Jul 17, 2023 4:56 pm

Hi CAsba,

I knew right away what you were after, but maybe I just misunderstood your term "shortcut to ACTIVATE the button".
But you meant a keyboard shortcut which does the same as clicking the button. :-)


Best

Klaus

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 » Mon Jul 17, 2023 5:06 pm

Using altKey and keyUp the whole thing should be extremely easy using a switch statement in a cardScript.

Nothing to get fussed about running an end-user through a decision tree.

This version uses ONLY numeric keys:
-
Screenshot_2023-07-17_20-05-49.png
-
Attachments
Button Selector.livecode.zip
Stack
(5.15 KiB) Downloaded 85 times
Last edited by richmond62 on Mon Jul 17, 2023 6:09 pm, edited 1 time in total.

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 » Mon Jul 17, 2023 5:42 pm

As it stands, the user must now stop using the keyboard, grab the mouse, and click on a button.
Late to this party, but CAsba, do you see that the others are suggesting a simple method so that the user never has to grab that mouse? The keyboard "shortcuts" all work on the specific buttons they are "mapped" to. And the final user action, after all the selections have been made, works similarly. You are under the misconception that the closing action cannot similarly be assigned a keyword shortcut.

I think I have this right; tell me if I do not.

And as Jacque mentioned, do not use the command key. It is too well used already. any of the other control-style keys are much better, since they rarely have pre-assigned functionality.

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 » Mon Jul 17, 2023 5:52 pm

Can you post a screen shot of the card with the buttons? Now that I understand the goal I think there may be a better way to do this but I'd like to see the UI.
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 » Mon Jul 17, 2023 6:17 pm

CAsba.
...that would be displayed under the button,
Once all five buttons have been "pressed" have the final button do something visually dramatic so the user will know it is now expected to press it. This is common to websites that one must fill in lots of required information before the final "Submit" button becomes visually "ready" to be pressed.

And I believe that the user SHOULD be made to grab that mouse, since the act of terminating the process is separate from the five button process itself.

And yes, a screen shot would be useful.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”