give user keyboard option instead of clicking
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
give user keyboard option instead of clicking
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
Hi CAsba,
you could add a -> commandkeydown tKey
handler to the card script of the card with your buttons:
or use the -> functionkey tKey command.
Usage like like the above example.
Best
Klaus
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
...
Usage like like the above example.
Best
Klaus
-
- Livecode Opensource Backer
- Posts: 9417
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: give user keyboard option instead of clicking
You can also use arrow keys to highlight buttons, followed by the ENTER key.
Re: give user keyboard option instead of clicking
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 ?
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
If you don't like the COMMAND key, use -> optionkeydown tKey
Re: give user keyboard option instead of clicking
Also not sure about this!?CAsba wrote: ↑Fri Jul 14, 2023 1:14 pmHmm,
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 ?
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?
-
- Livecode Opensource Backer
- Posts: 9417
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: give user keyboard option instead of clicking
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.
Mind you, if he has LOTS of keys (some of which are HIDDEN) things get very queer indeed.
-
- 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
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
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
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
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 9417
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: give user keyboard option instead of clicking
-
- Attachments
-
- keyCoder.livecode.zip
- Stack.
- (9.87 KiB) Downloaded 78 times
Re: give user keyboard option instead of clicking
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.
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
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
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
-
- Livecode Opensource Backer
- Posts: 9417
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: give user keyboard option instead of clicking
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:
- -
Nothing to get fussed about running an end-user through a decision tree.
This version uses ONLY numeric keys:
- -
- 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.
-
- 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
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.As it stands, the user must now stop using the keyboard, grab the mouse, and click on a button.
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
-
- 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
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
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
CAsba.
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
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....that would be displayed under the button,
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