Page 1 of 4
give user keyboard option instead of clicking
Posted: Fri Jul 14, 2023 12:37 pm
by CAsba
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 ?
Re: give user keyboard option instead of clicking
Posted: Fri Jul 14, 2023 12:56 pm
by Klaus
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
Re: give user keyboard option instead of clicking
Posted: Fri Jul 14, 2023 12:59 pm
by richmond62
You can also use arrow keys to highlight buttons, followed by the ENTER key.
Re: give user keyboard option instead of clicking
Posted: Fri Jul 14, 2023 1:14 pm
by CAsba
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 ?
Re: give user keyboard option instead of clicking
Posted: Fri Jul 14, 2023 1:19 pm
by Klaus
If you don't like the COMMAND key, use ->
optionkeydown tKey 
Re: give user keyboard option instead of clicking
Posted: Fri Jul 14, 2023 1:28 pm
by Klaus
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!?

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?
Re: give user keyboard option instead of clicking
Posted: Fri Jul 14, 2023 2:30 pm
by richmond62
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.
Re: give user keyboard option instead of clicking
Posted: Fri Jul 14, 2023 10:32 pm
by jacque
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.
Re: give user keyboard option instead of clicking
Posted: Sat Jul 15, 2023 8:23 am
by richmond62
Re: give user keyboard option instead of clicking
Posted: Mon Jul 17, 2023 3:26 pm
by CAsba
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.
Re: give user keyboard option instead of clicking
Posted: Mon Jul 17, 2023 4:56 pm
by Klaus
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
Re: give user keyboard option instead of clicking
Posted: Mon Jul 17, 2023 5:06 pm
by richmond62
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:
-
-
Re: give user keyboard option instead of clicking
Posted: Mon Jul 17, 2023 5:42 pm
by dunbarx
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
Re: give user keyboard option instead of clicking
Posted: Mon Jul 17, 2023 5:52 pm
by jacque
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.
Re: give user keyboard option instead of clicking
Posted: Mon Jul 17, 2023 6:17 pm
by dunbarx
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