Control key vs right mouse click: Pros & cons?

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Control key vs right mouse click: Pros & cons?

Post by RCozens » Wed Aug 25, 2021 8:48 pm

Several of Serendipity Editor's buttons modify their behavior if the control key is down at mouseUp. Since my user interface is point-&-click, it occurs to me that checking for the right mouse button instead of the control key would be more elegant.

Is there a way to determine the mouse's right button status? (I presume there is, but I cannot identify it.)

Any opinions as to which is the better approach?
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.

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

Re: Control key vs right mouse click: Pros & cons?

Post by richmond62 » Wed Aug 25, 2021 8:55 pm

SShot 2021-08-25 at 22.53.11.png
-
cardScript [Rocket Science]

Code: Select all

on mouseUp MUP
   put ("Mouse button" && MUP) into fld "ff"
end mouseUp
Attachments
Mousequetier.livecode.zip
Here's the stack.
(962 Bytes) Downloaded 114 times

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

Re: Control key vs right mouse click: Pros & cons?

Post by Klaus » Wed Aug 25, 2021 8:59 pm

Hi Rob,

"mouseup" etc. comes with a parameter, the number of the clicked mousebutton!
1 = "normal" click
2 = middle mousebutton, mostly used on 'NIX
3 = RIGHT click
So you could modify the MOUSEUP handlers accordingly:

Code: Select all

on mouseup tMouseButton
  if tMouseButton = 3 then
   ## RIGHT click, do your thing...
 end if
end mouseup
You get the picture. :-)


Best

Klaus

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

Re: Control key vs right mouse click: Pros & cons?

Post by RCozens » Thu Aug 26, 2021 12:00 am

Thanks for showing me how to do this. Before I do it, though, I'm hoping to hear from others about the tradeoffs between using the mouse button or the control key to modify a button's response.
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.

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: Control key vs right mouse click: Pros & cons?

Post by kdjanz » Thu Aug 26, 2021 12:38 am

Use both. Check the control key and check the mouse button so that either will work.

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

Re: Control key vs right mouse click: Pros & cons?

Post by dunbarx » Thu Aug 26, 2021 2:36 am

What everyone said.

The biggest difference, if I understand your point, is that using one of the "control" keys is an extra step, that is, it is not just clicking one of the buttons on a mouse. The benefit is, of course, more options, more possibilities.

Craig

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

Re: Control key vs right mouse click: Pros & cons?

Post by RCozens » Thu Aug 26, 2021 5:30 pm

dunbarx wrote:
Thu Aug 26, 2021 2:36 am
What everyone said.

The biggest difference, if I understand your point, is that using one of the "control" keys is an extra step, that is, it is not just clicking one of the buttons on a mouse. The benefit is, of course, more options, more possibilities.

Craig
Now that I've thought about it, I agree...especially in a point-and-click interface.

I will make the change today and try it.

Thanks all,
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.

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

Re: Control key vs right mouse click: Pros & cons?

Post by richmond62 » Thu Aug 26, 2021 5:43 pm

Several of Serendipity Editor's buttons modify their behavior if the control key is down at mouseUp. Since my user interface is point-&-click, it occurs to me that checking for the right mouse button instead of the control key would be more elegant.
Mr Crude Functionalism here asking WTF "elegant" means.

Surely what is more to the point is end-user ease of use?

I always have a sneaking suspicion that putting code "elegance" first is a bit like playing with your wobbly bits in private,
while end-user ease of use really is of more lasting value . . .

Of course if one can manage end-user ease of use while using elegant code: go for it.

It is dead-easy to check if the CTRL key is down . . .

Let's have a "hot and sweaty fantasy" with some fairly random code:

Code: Select all

on mouseUp MUP
if controlKey() is down then
  if MUP >2 then
  put "Well I never, the controlKey is down and you pressed the right button on your mouse"
  end if
  end if
  end mouseUp

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Control key vs right mouse click: Pros & cons?

Post by stam » Fri Aug 27, 2021 2:32 am

RCozens wrote:
Wed Aug 25, 2021 8:48 pm
Several of Serendipity Editor's buttons modify their behavior if the control key is down at mouseUp...
Is there a way to determine the mouse's right button status?...
On the face of it a simple question - but some clarification is needed.
- Are you trying to react to a right-click?
- Or are you checking to see if the control key is pressed, eg a control-right-click as well?
(keeping in mind that on Mac the effect control-left-click is equivalent to a right-click, but probably not on any other platform).

If just checking for 'right-click' then i would agree with Klaus that checking for the button parameter = 3 is the better option. Most mouse handlers include a parameter that provides you with an integer 1, 2 or 3 corresonding to the left, middle or right mouse button, to tell you which was clicked.
On Mac, control-left click sets this to 3, i.e. a right mouse click, hence Klaus' example:
Klaus wrote:
Wed Aug 25, 2021 8:59 pm

Code: Select all

on mouseup tMouseButton
  if tMouseButton = 3 then
   ## RIGHT click, do your thing...
 end if
end mouseup
The reason this is more 'elegant' is that that it covers both right-clicking and control-left-clicking (on Mac), if that is your desired action.

However, if you are not intending to do a 'right-click' with the control-mouseUp and if your target is not mac, or indeed if you want to do a control-right-click etc, then you can check controlKey() as Richmond recommends.

Hope that makes sense ;)
Stam

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

Re: Control key vs right mouse click: Pros & cons?

Post by richmond62 » Fri Aug 27, 2021 11:31 am

On Macintosh a mouse left-click with the CTRL key depressed
gives you the same contextual menu that you get from a
mouse right-click.

In the FINDER at least.

HOWEVER, for the sake of argument, in this textField that I am currently writing into [Browser = Brave].
a mouse right-click gives me a contextual menu, but a mouse left-click with the CTRL key depressed does
NOT work BECAUSE I have chosen to swap my COMMAND and CTRL keys in the system settings:
-
SShot 2021-08-27 at 13.29.44.png
-
As a programmer has no idea about how an end-user has mucked around with their keyboard settings
I would tend to use mouse button 3 instead of leveraging the CTRL key.

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Control key vs right mouse click: Pros & cons?

Post by stam » Fri Aug 27, 2021 12:01 pm

Remapping the command and control keys doesn't mean the 'control key' won't work. It just means the key labelled as control is actually mapped to the command key.

Depressing the Command key which has been remapped to the control key will achieve he same effect as clicking control-mouseUp on an unmodified system, because your app doesn't care about your key remapping; it just receives the control and mouseUp events.
Equally i can remap my left and right mouse buttons. If i do this, it should make sense to expect a right click when click the left mouse button, but from my app point of view mouseButton = 3 would then correspond to the left mouse button.

The real question is what the OP is intending to do. I suspect it's just simulating a right-click on 1-button mice, in which case checking for mouseButton = 3 is the safest option that covers all options.

If on the other hand the intention is to check for the control key no matter what mouse button is clicked (for example, if the author wants to react to control-right-click) then that requires checking controlKey() as well.

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

Re: Control key vs right mouse click: Pros & cons?

Post by richmond62 » Fri Aug 27, 2021 12:04 pm

It just means the key labelled as control is actually mapped to the command key.
I know that, and you know that, BUT does the average end-user know that, and is the keyboard remapping
on Macintosh consistent across all applications?

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Control key vs right mouse click: Pros & cons?

Post by stam » Fri Aug 27, 2021 12:09 pm

Not questioning your knowledge, only responding to your post.
Apps do not remap function keys on Mac. It is a very safe bet to assume command, option(alt), control and shift keys will always do what it says on the tin, unless the end user makes a non-trivial effort to change this.

One would assume if an end-user undertakes this quite uncommon practice then they should be aware of the consequences.
If not, they shouldn't be screwing with their system ;) (life lesson right there...)

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

Re: Control key vs right mouse click: Pros & cons?

Post by richmond62 » Fri Aug 27, 2021 12:11 pm

simulating a right-click on 1-button mice
Pause for muffled chuckles.

I thought I was being "no end of posh", when, in 1996 I bought a 3 button
mouse and connected it to my Performa 5200 LC running macOS 8.5 that I had
just bought in downtown Jeddah, KSA.

But this was mainly being bogged down in Saudi Arabia without any internet or any other
way of knowing what on earth was happening in the rest of the world, I hadn't the foggiest
that my adoption of a multi-button mouse was way behind the curve.

So, who is using a single-button mouse these days?
-
mishka.jpeg
mishka.jpeg (6.83 KiB) Viewed 5295 times
-
Already outdated before it was released.

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

Re: Control key vs right mouse click: Pros & cons?

Post by richmond62 » Fri Aug 27, 2021 12:13 pm

this quite uncommon practice
Dunno how uncommon: certainly a lot of people I know who work with computers running Linux, Windows and Macintosh
find swapping the COMMAND and CTRL keys on a Mac, so things are fairly consistent with Linux and Windows, is a great
boon to productivity, and cuts down on the cursing considerably.

Life lesson there. :wink:

Post Reply

Return to “Talking LiveCode”