Change button label by pressing the command key

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Fjord
Posts: 132
Joined: Sat Dec 06, 2008 6:18 pm
Location: France

Re: Change button label by pressing the command key

Post by Fjord » Fri Jun 03, 2022 11:19 pm

@Fjord. But do you see how this can work?
Sure. I used HC a lot when I was a bit younger, 30+ years ago. :D
--
François

mtalluto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 125
Joined: Tue Apr 11, 2006 7:02 pm
Location: Seattle, WA
Contact:

Re: Change button label by pressing the command key

Post by mtalluto » Sat Jun 04, 2022 12:15 am

I would consider changing Richmond's fine code every so slightly to use on mouseMove and apply a flag (optional). You may not need the flag. It will depend on what you plan to do next. The mouseMove check may be enough.

Code: Select all

//script local
local sTrackCommandKey

on mouseMove
   if the commandKey is down then
      put true into sTrackCommandKey
      set the label of btn "XYZ" to "CmdKey Down"
   else
      put false into sTrackCommandKey
      set the label of btn "XYZ" to "CmdKey Up"
   end if
end mouseMove

//somewhere in the handling of the popup
//you may set the flag to false as well
//as in...     put false into sTrackCommandKey
Mark Talluto
--
Canela
design - develop - deploy: https://appli.io
Database and Cloud for LiveCode Developers: https://livecloud.io
Company: https://canelasoftware.com

Fjord
Posts: 132
Joined: Sat Dec 06, 2008 6:18 pm
Location: France

Re: Change button label by pressing the command key

Post by Fjord » Sat Jun 04, 2022 8:05 am

@mtalluto: I do not really understand; what's the mouse got to do with the problem I stated at the start of this thread?
--
François

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

Re: Change button label by pressing the command key

Post by richmond62 » Sat Jun 04, 2022 11:35 am

Not much.

AND I, for one, cannot see what the 'sweat' is about using IDLE, as, for the sake of argument, even my maist manky Linux box has half a Gig of RAM.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9656
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Change button label by pressing the command key

Post by dunbarx » Sat Jun 04, 2022 2:31 pm

Richmond.

It isn't RAM, it is processor overhead. "Idle" messages are sent constantly at the IdleTicks rate. If they are not trapped, they pass relatively unseen through the system. But if they are trapped, even if the handler itself never fires, something like:

Code: Select all

on idle
if the sun has already burned out then..
the system notices, and time is taken to see what is going on in that handler. This may impact processor-intense processes.

So idle is there, you just have to be aware of its ramifications.

Craig
Last edited by dunbarx on Sat Jun 04, 2022 10:06 pm, edited 1 time in total.

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

Re: Change button label by pressing the command key

Post by richmond62 » Sat Jun 04, 2022 3:09 pm

This may impact processor-intense processes.
Well, as one has a SHIFT, an ALT/OPTION key, and a CTRL key, as well as whole slew
of Function keys available to one with Macintosh there should not be any real reason to
have to muck around with the COMMAND key at all.

Fjord
Posts: 132
Joined: Sat Dec 06, 2008 6:18 pm
Location: France

Re: Change button label by pressing the command key

Post by Fjord » Sat Jun 04, 2022 5:50 pm

@richmond62: sorry, I disagree.
1º shift and option have the same problem as the command key: you can’t get the fact that they are pressed without pressing another key (AFAIK)
2° function keys: I don’t know how to use these but that’s drifting from my original post.
All I was thinking of in my original post was, having two variants of the same script in the same btn, one to act on a single cd, one to act on all cds. Basically, I can have 2 different btns; I only wanted to save space on the cd.
--
François

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

Re: Change button label by pressing the command key

Post by FourthWorld » Sat Jun 04, 2022 6:58 pm

The mouseMove solution is good, but, though it's more efficient than idle, unless the trigger action is dependent on the mouse moving it may be possible that it won't trigger when needed.

Idle is less efficient, but probably not prohibitively so. Changing a button label is a small thing computationally, and the unused messages require so little CPU they probably aren't noticeable, and perhaps not even easily measurable on sufficiently fast systems.
Fjord wrote:
Sat Jun 04, 2022 5:50 pm
Basically, I can have 2 different btns; I only wanted to save space on the cd.
The idle solution will do what you're looking for, but is this app for yourself or to share with others?

The bigger challenge here seems less a technical concern in the messaging as much as a usability concern with having to remember a hidden option and also the means of revealing that option.

We spend so much time making our own software it's easy to forget how much time users spend with software that isn't ours. :) So being as gentle as possible with cognitive load goes a long way toward user satisfaction; users are busy, often distracted, and have to deal with a lot of systems all day that demand a lot of their attention.

Having both actions visible as separate buttons lets the user know there are two actions, without having to remember anything.

If available space is so critically limited it just isn't practical to display both action buttons at once, two options that come to mind are:

- Consider icons instead of labels for the buttons (if such images convey the action clearly).

- Consider putting both labels in a pulldown Action menu, where you could also add any other functionality you might think of later on.

But of course these notions are from someone who knows neither the UI nor the use case, so your good judgement with your hands-on knowledge is the best arbiter.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Change button label by pressing the command key

Post by richmond62 » Sat Jun 04, 2022 8:10 pm

"sorry"

Don't be, ongoing, positive, discussion does not need apologies.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9656
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Change button label by pressing the command key

Post by dunbarx » Sat Jun 04, 2022 10:22 pm

@fJord
2° function keys: I don’t know how to use these but that’s drifting from my original post.
Try this on a new card:

Code: Select all

on functionKey tkey
   answer tkey
end functionKey
Note that you first have to go to the"Short Cuts" pane in the "keyBoard" pane in "System Preferences" and check the "Use F1, F2, etc keys..."

This will give you a one-keyPress solution, as you wanted with the commandKey. This is because LC has a "functionKey" message.

I have always wondered if I really know how things work. The label of that system preferences button seems to tell me that it really ought to be unchecked, not checked. I should have posted this to the beginners section. Is there a LC property that overrides that system preference setting? I bet there is, since I assume I don't know how things work.

Craig

mtalluto
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 125
Joined: Tue Apr 11, 2006 7:02 pm
Location: Seattle, WA
Contact:

Re: Change button label by pressing the command key

Post by mtalluto » Tue Jun 07, 2022 8:55 pm

Fjord wrote:
Sat Jun 04, 2022 8:05 am
@mtalluto: I do not really understand; what's the mouse got to do with the problem I stated at the start of this thread?
Hi François. If there is no other user input than to press the commandKey, my suggestion will not help.
If the user moves or clicks their mouse during the check, then moveMove will catch the action.

If you are not expecting the user to move the mouse or click anywhere while doing a command key is down check, my suggestion will not help.
Mark Talluto
--
Canela
design - develop - deploy: https://appli.io
Database and Cloud for LiveCode Developers: https://livecloud.io
Company: https://canelasoftware.com

Fjord
Posts: 132
Joined: Sat Dec 06, 2008 6:18 pm
Location: France

Re: Change button label by pressing the command key

Post by Fjord » Tue Jul 05, 2022 11:30 am

@Richard:
The bigger challenge here seems less a technical concern in the messaging as much as a usability concern with having to remember a hidden option and also the means of revealing that option.
We spend so much time making our own software it's easy to forget how much time users spend with software that isn't ours. :) So being as gentle as possible with cognitive load goes a long way toward user satisfaction; users are busy, often distracted, and have to deal with a lot of systems all day that demand a lot of their attention.
Having both actions visible as separate buttons lets the user know there are two actions, without having to remember anything.
I agree 110% ! This app is just for myself; and even then, I may find that I forgot the double meaning of the button.
--
François

Fjord
Posts: 132
Joined: Sat Dec 06, 2008 6:18 pm
Location: France

Re: Change button label by pressing the command key

Post by Fjord » Tue Jul 05, 2022 11:38 am

@Dunbar:
Try this on a new card:
CODE: SELECT ALL
on functionKey tkey
answer tkey
end functionKey
Note that you first have to go to the"Short Cuts" pane in the "keyBoard" pane in "System Preferences" and check the "Use F1, F2, etc keys..."
Interesting to know that… except for the fact that I couldn't find the "Use F1…" in System Prefs > Keyboard > Shortcuts. But no problem, for now.
Thanks for the info.
--
François

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

Re: Change button label by pressing the command key

Post by richmond62 » Tue Jul 05, 2022 11:45 am

I couldn't find the "Use F1…" in System Prefs > Keyboard > Shortcuts.
Nor could I: and just to be ridiculous, I checked in Mac OS 10.6.8 as well as Mac OS 12.5 beta 4. 8)

It just so happens I have 2 Macs running at the moment with those operating systems . . .

. . . it is all to do with recovering the contents of documents written in ClarisWorks 5 . . . 'nuff said.
-
SShot 2022-07-05 at 13.48.57.png
-
Not particularly groovier than fishing for code in old HyperCard stacks. :oops:
Last edited by richmond62 on Tue Jul 05, 2022 7:36 pm, edited 1 time in total.

RCozens
Posts: 138
Joined: Thu Aug 05, 2021 6:42 am
Location: Manchester, CA USA

Re: Change button label by pressing the command key

Post by RCozens » Tue Jul 05, 2022 5:28 pm

Fjord wrote:
Thu Jun 02, 2022 9:49 pm
Hi,
I'm wondering how / if I can change a button label just by holding, say, the command key. I have a button script along these lines:
on mouseUp
   if the eventCommandKey is up then
     do something on the current card
  else do the same thing on all cards
end mouseUp
It would be much neater to have the button label change from 'do something' to 'do something to all' whenever the command key is pressed. But I can't find a way, other than using a 'on idle' handler (which is not recommended) or some kind of timer with 'send'.
Can one trap the pressing of the command key alone?
Hi François,

From your example, it appears to me that your objective is to change the action of a button triggered by a mouseUp message. If the user changes the label of a button based on a keyboard action, he/she must still initiate the action via the mouse.

My approach to modifying a button's mouseUp action uses the right mouse button to trigger an alternative to the main function of the button:

Code: Select all

on mouseUp whichButton
   -- this is pseudo code, not LC syntax
   if whichButton is not 3 then  -- 3 = right button
      do something on the current card
  else do the same thing on all cards
end mouseUp
I use this technique extensively in Serendipity Editors for Images & Icons, and am very happy with the resulting user experience. My stack is posted on the Made With LiveCode Forum if you would like to explore this technique. If you download the stack, right click on the About image to see how the behavior of various buttons changes in response to a right click.

Cheers!
Rob Cozens dba Serendipity Software Company
Manchester, CA USA

Each new generation gives more attention to the man-made world...
and less attention to the world that made man.

Post Reply

Return to “Talking LiveCode”