Assigning a keyboard shortcut to a button

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: Klaus, FourthWorld, heatherlaine, kevinmiller

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3458
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Assigning a keyboard shortcut to a button

Post by richmond62 » Fri Mar 30, 2018 2:18 pm

Who needs keyboard shortcuts in "apps"
My whole Devawriter Pro depends on keyDown, keyUp and keySideways (this last one
is an undocumented feature). 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3458
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Assigning a keyboard shortcut to a button

Post by richmond62 » Fri Mar 30, 2018 3:53 pm

On a more serious point . . .

There are disabled people who don't have the motor control to manage a mouse
or a trackpad, but can cope with keys on a keyboard.

I am currently in my school where the keyboards are like this:
kb.JPG
They are just perfect for small fingers and thumbs. :D

bogs
Posts: 3698
Joined: Sat Feb 25, 2017 10:45 pm

Re: Assigning a keyboard shortcut to a button

Post by bogs » Fri Mar 30, 2018 4:17 pm

richmond62 wrote:
Fri Mar 30, 2018 8:19 am
You and I are apparently in the same choir
Much as I have tried, all my life, I have never managed to sing in tune. 8)
Like I said, in the same choir for sure, I couldn't carry a tune if it was in a bucket strapped to my arms :oops:
Side note: love the keyboard, might even work for me :D

Ultimately, if I ever get past spending what they are asking, I'd love to have this keyboard:
Selection_003.png
Selection_003.png (61.85 KiB) Viewed 1370 times
AxWald wrote:
Fri Mar 30, 2018 1:38 pm
Hi,
richmond62 wrote:
Thu Mar 29, 2018 7:41 pm
[...] the thing is called a "shortcut" and not an "accelKey"? [...]
This depends of the setting in the preferences:
"Property labels are:"

"Description of option" => "Shortcut"
"Name of LC property" => "accelKey"
First, I want to thank you AxWald, much like Jean-Marc up there, I had completely forgotten I always set the properties to the property name in preferences. I think especially when learning about Lc, it is the better faster solution, I know it helped me immensely.

I am sure what follows is going to sound, well, poorly, it is not aimed at you, but more at the universe in general.
And yes, they omitted it completely in the 8 versions prop palette. Who needs keyboard shortcuts in "apps", anyways?
Well, probably anyone who programs with a keyboard in mind, or has been programming longer than say, 6 months ago, or maybe anyone who doesn't program for mobile thingies (yes, a few of us don't even own any mobile thingies), those people may want to program for keyboard shortcuts for other people who don't want to or can't reach for a mouse as Richmond correctly pointed out.

I really can't imagine the reason for taking it out of the properties box, which is where it has been since what, Mc? Hypercard? Every other IDE on the planet? I'd never have guessed someone hated it that much. If someone knows the reason *why* it was taken out, I'd love to hear it. Well, probably not, but since its almost time for my blood pressure meds anyway, go ahead so I can fume over it and move on :twisted:
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3458
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Assigning a keyboard shortcut to a button

Post by richmond62 » Fri Mar 30, 2018 6:38 pm

One thing you need to be very careful with is assigning a keyboard shortcut
that "mucks about" with the underlying OS.

When I was setting up my second stack with shiftKey + F1 I initially tried altKey + F1 and ran into
all sorts of trouble. 8)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3458
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Assigning a keyboard shortcut to a button

Post by richmond62 » Fri Mar 30, 2018 6:57 pm

While the kids in my school use those KeyNeeds polychromic "horrors", they lack Function keys, so
I have one of these attached to my "teacher's box":

https://www.ebay.com/itm/Visually-Impai ... SwjqVZKsbA

bogs
Posts: 3698
Joined: Sat Feb 25, 2017 10:45 pm

Re: Assigning a keyboard shortcut to a button

Post by bogs » Fri Mar 30, 2018 7:24 pm

richmond62 wrote:
Fri Mar 30, 2018 6:38 pm
One thing you need to be very careful with is assigning a keyboard shortcut
that "mucks about" with the underlying OS.

When I was setting up my second stack with shiftKey + F1 I initially tried altKey + F1 and ran into
all sorts of trouble. 8)
That is true enough, but there are certain shortcuts you more or less expect to put in, like an Exit button, New, etc. I can't remember the last IDE I used that didn't have the facility to just check the box and type the key, or give you that property setting by typing something like 'E&xit' for the name/label.

Why anyone would change a formula that has been working without issues for the last 20+ years is beyond me. Guess I am just not one of the cool kids :roll: (going to choir practice now).
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3458
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Assigning a keyboard shortcut to a button

Post by richmond62 » Fri Mar 30, 2018 8:18 pm

Why anyone would change a formula that has been working without
After you have been "Living with LiveCode"

[c.f. Cooking with Fernet Branca: https://www.theguardian.com/books/2004/ ... anreview10 . . . to be savoured, that book]

for a while (I'm on about 16 tears), you begin to realise that, rather like the Uncle you
asked why he always told you to cut your slice of bread into quarters and said
"Because I said so." . . .

Or, like the Grandmother who sends you £50 and says you can spend it on whatever
you want as long as it is something to do with what you are studying at University . . .

. . . Well, never mind . . . 8)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6786
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Assigning a keyboard shortcut to a button

Post by FourthWorld » Fri Mar 30, 2018 10:19 pm

bogs wrote:
Fri Mar 30, 2018 7:24 pm
That is true enough, but there are certain shortcuts you more or less expect to put in, like an Exit button, New, etc. I can't remember the last IDE I used that didn't have the facility to just check the box and type the key, or give you that property setting by typing something like 'E&xit' for the name/label.

Why anyone would change a formula that has been working without issues for the last 20+ years is beyond me. Guess I am just not one of the cool kids :roll: (going to choir practice now).
Menu shortcuts are universally recommended by the various OS HIGs, and well supported in LC. You'll see them in the Menu Builder.

Shortcuts for button actions not found in a menu bar are rarely used. They were common in early versions of Motif, where MetaCard (the original name for this engine) supported them. I don't recall seeing any modern HIG recommending them. Unlike menus, where shortcuts are explicitly noted, shortcuts in buttons are invisible to the user, reducing if not eliminating any value they might offer.

That said, the team understands that many devs may want to use them, so they have not deprecated the feature. You can still use them if you want to in your scripts, like any other language element.

Remember that an Inspector is a specific design choice to provide quick access to the most commonly-used properties. As such, the LC Inspector does not attempt to provide GUI controls for every property the engine supports for every object type.

Some IDEs use a Property Sheet instead of an inspector. Prop Sheets generally do provide a complete listing of all properties for a given object type, but at the cost of additional cognitive load: with so many properties so seldom used, it can impede workflow in accessing the ones you need.

Personally, I prefer erring on the side of completeness, so I made a Prop Sheet many years ago which I still often use. You can download it here:
http://fourthworld.net/revnet/devolutio ... ops.rev.gz

It doesn't currently handle widgets, since widgets are the one class of objects which do not expose their properties through a call to "the properties". When there is one universal way to obtain a list of properties I'll update my Prop Sheet, and I believe the team is exploring a solution for that.

Tip for devolution users: If you prefer using the Property Sheet (or any other such tool) instead of LC's Inspector, you can reassign devolution's "Inspector" button to launch any Plugin you want; this is true for the other tool launcher buttons as well ("Tools", "Browser", and "Message"). Assignment for this is done in the "devolution Options" pane of the flyout window that appears when clicking the topmost flyout indicator arror.

devolution can be downloaded here:
http://fourthworld.com/products/devolution/
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

bogs
Posts: 3698
Joined: Sat Feb 25, 2017 10:45 pm

Re: Assigning a keyboard shortcut to a button

Post by bogs » Sat Mar 31, 2018 5:20 pm

FourthWorld wrote:
Fri Mar 30, 2018 10:19 pm
Shortcuts for button actions not found in a menu bar are rarely used.
[1.]They were common in early versions of Motif, where MetaCard (the original name for this engine) supported them. I don't recall seeing any modern HIG recommending them.
[2.]Unlike menus, where shortcuts are explicitly noted, shortcuts in buttons are invisible to the user, reducing if not eliminating any value they might offer.
After reading this, I'm not sure we're talking about the same thing even, although I can't imagine too many ways we couldn't be.
  1. Shortcuts in buttons were common in more than Motif, they were in just about every linux dm I can remember and in all versions of windows at least up till 7 or 8, I don't play with 10 very much but doubt it is common there anymore since it is such an awkward interface to me. I can't really speak to Mac, not being an often enough user of that OS.
  2. Shortcuts in buttons were never invisible to the user, much like a menu shortcut, they are denoted by an underlined key letter that corresponds to the letter used in the shortcut displayed in the label of the button. If they weren't, then I'd agree it would be stupid to have them, after all, how would your user know there was one if it isn't hinted at?
    Selection_004.png
    *Edit - I forgot to include the *current* linux model, XFCE4 style -
    Selection_004.png
They were most commonly found in dialogs, but if your main interface used buttons you could also find them there, and a number of my interfaces used them *especially* when I was coding for a keyboard predominant user or if my interface had no menus (plenty of them don't require one).
Remember that an Inspector is a specific design choice to provide quick access to the most commonly-used properties. As such, the LC Inspector does not attempt to provide GUI controls for every property the engine supports for every object type.
If it was "common" enough to include in every version of Lc in a much smaller property palette up till NOW, I'd expect it to be there if I were using a newer IDE. We're not talking about adding some new kind of thing here, or "every property ever made", we're talking about something that has been there since the start and, pertinent to this topic, was being requested when it shouldn't be a mystery on how to reach it.

I sure hope your not trying to say that with the massive increase in size that the palette has taken, including a single line property was taking up too much space ?!

The propSheet plugin looks interesting, I'll dig into that more later, thanks for popping it up here :D I just made a list of all the props I could find that aren't in the palette, but I wouldn't expect to have to tell a new comer to code in one that has literally been around since the dawn of time.
Last edited by bogs on Sun Apr 01, 2018 4:12 am, edited 1 time in total.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5084
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Assigning a keyboard shortcut to a button

Post by jacque » Sat Mar 31, 2018 5:51 pm

The inspector was rewritten from scratch recently to support dynamic content, specifically for the inclusion of widgets which might be different for every user. The nature of the beast required changes to its appearance and content. Early versions were missing more than just button shortcuts, and based on user feedback some of the omissions were added back in. Some of my suggestions were not accepted because the layout challenges were too great. Once the inspector became something other than a static layout, compromises had to be made.

But if this is important to you, a feature request in the QCC would be in order. Several omissions were added back in after enough users indicated it would be useful.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

bogs
Posts: 3698
Joined: Sat Feb 25, 2017 10:45 pm

Re: Assigning a keyboard shortcut to a button

Post by bogs » Sat Mar 31, 2018 7:24 pm

Thank you for the explanation Jacque, while I might not agree with the approach, at least that makes some sort of sense. All I can say is I hope it turns out alright for everyone else.

*Edit - I changed my mind about submitting it. I might never rely on 8.x upwards, but you can never tell I suppose.
21133.
Image

bambster
Posts: 4
Joined: Thu Mar 29, 2018 4:26 pm

Re: Assigning a keyboard shortcut to a button

Post by bambster » Tue Apr 03, 2018 1:52 pm

Hey everyone!

So I finally got to play around with the shortcut functionality you provided me with. Works like a charm. The key combinations (e.g. Ctrl + shift + F1) work as well.

I quickly ran into one problem though: the script only seems to recognize the first assigned shortcut. In the case below 'if RUP = 65474' (which is F5). Pressing F5 triggers the button "btnTeamWin1" and gives me visual feedback that it clicked "the loc of button "btnTeamWin1"".

Code: Select all

on rawKeyUp RUP           
         if RUP = 65474 then
            click at the loc of button "btnTeamWin1"
            if RUP = 65475 then
               click at the loc of button "btnTeamWin2"               
            else
               pass rawKeyUp
            end if
         end if   
end rawKeyUp
Pressing F6 (65475) happens to do nothing at all. If I put it first though it works again and triggers "btnTeamWin2".

I tried splitting the 2 shortcuts into to 2 functions but that doesn't solve the problem I'm afraid.

Code: Select all

//F5
on rawKeyUp RUP           
   if RUP = 65474 then
      click at the loc of button "btnTeamWin1"
      else
         pass rawKeyUp
      end if     
end rawKeyUp

//F6
on rawKeyUp RUP           
   if RUP = 65475 then
      click at the loc of button "btnTeamWin2"
   else
      pass rawKeyUp
   end if   
end rawKeyUp
Only the first key gets recognized.

This is probably pretty basic stuff, but after fiddeling around for the last couple of hours and not getting anything to work I'm up for cheating again...

Could anyone point me in the direction of what I am missing? :(

Thanks in advance!
bambster

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

Re: Assigning a keyboard shortcut to a button

Post by Klaus » Tue Apr 03, 2018 2:12 pm

Hi bambster,

if you have two IDENTICAL named handlers in the same script, LC will only execute the first one it encounters! Use a SWITCH structure to tell LC what you want:

Code: Select all

on rawKeyUp RUP 
  switch RUP          
  case 65474
      click at the loc of button "btnTeamWin1"
  break       
  case 65475
      click at the loc of button "btnTeamWin2"
  break
  ## You can catch more key codes in this handler if neccessary by just adding their "cases" like
  ## case 12345
  ##   dothisorthat
  ## break
  ## etc...

  ## What to do if none of the cases above apply:
  default
      pass rawKeyUp
   break
 end switch  
end rawKeyUp
Best

Klaus

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 3458
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Assigning a keyboard shortcut to a button

Post by richmond62 » Tue Apr 03, 2018 2:40 pm

OR . . .

catch one key with rawKeyDown, and the second one with rawKeyUp.

My Devawriter Pro features switch statements with up to 6,000 possible case situations.

But, hey, I'm a hard case 8)

bambster
Posts: 4
Joined: Thu Mar 29, 2018 4:26 pm

Re: Assigning a keyboard shortcut to a button

Post by bambster » Tue Apr 03, 2018 7:21 pm

Klaus wrote:
Tue Apr 03, 2018 2:12 pm
Hi bambster,

if you have two IDENTICAL named handlers in the same script, LC will only execute the first one it encounters! Use a SWITCH structure to tell LC what you want:

Code: Select all

on rawKeyUp RUP 
  switch RUP          
  case 65474
      click at the loc of button "btnTeamWin1"
  break       
  case 65475
      click at the loc of button "btnTeamWin2"
  break
  ## You can catch more key codes in this handler if neccessary by just adding their "cases" like
  ## case 12345
  ##   dothisorthat
  ## break
  ## etc...

  ## What to do if none of the cases above apply:
  default
      pass rawKeyUp
   break
 end switch  
end rawKeyUp
Best

Klaus
Thanks so much Klaus, this works perfectly! :)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”