Recent

Author Topic: detecting Command Click  (Read 974 times)

dbannon

  • Hero Member
  • *****
  • Posts: 1274
    • tomboy-ng, a rewrite of the classic Tomboy
detecting Command Click
« on: August 13, 2020, 09:20:04 am »
Please help a Mac-a-phobe.

In my app, a right click pops up a menu.   But on the Mac, there is no right click and by convention, users hold the Command Key down and then click with the poor crippled mouse they use. 

But the OnClick event does not tell me the state of the keyboard, seems I need to detect a key-down event, if its the Command key set a boolean and then if I detect a key-up event, if its the Command key unset that boolean.

If the use clicks while that boolean is set, its a command click - wow, is there an easier (and less obtrusive for non Mac) way to do it ?

Would be better to look to see if the command key is down at the time of a click but that does not seem possible to me ....

Davo

Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1225
  • Former Delphi 1-7, 10.2 User
Re: detecting Command Click
« Reply #1 on: August 13, 2020, 09:41:48 am »
CTRL-click = Right click (to get, eg, a context menu).
Lazarus 2.1 r64368 FPC 3.3.1 r48100 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r64392 3.3.1 Jan 13 21:24 macOS 11.1 aarch64 Xcode 12.3
Lazarus 2.1 r61574 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 3.2.0 Win10 Parallels VM

dbannon

  • Hero Member
  • *****
  • Posts: 1274
    • tomboy-ng, a rewrite of the classic Tomboy
Re: detecting Command Click
« Reply #2 on: August 13, 2020, 10:43:54 am »
Yeah, of course !  Thanks Trev !

Code: Pascal  [Select][+][-]
  1. if {$ifdef DARWIN} (ssCtrl in Shift) {$ELSE} (Button = mbRight) {$ENDIF}

Interesting it should be Control not the Command I thought ......

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Soner

  • Full Member
  • ***
  • Posts: 209
Re: detecting Command Click
« Reply #3 on: August 13, 2020, 11:05:03 am »
Macos supports right click, do this or say the user:
Hold [ctrl]-Key + Mouse Button left click = Mouse button right click.

You have not to change your application code.

VTwin

  • Hero Member
  • *****
  • Posts: 943
  • Former Turbo Pascal 3 user
Re: detecting Command Click
« Reply #4 on: August 17, 2020, 01:03:32 am »
But on the Mac, there is no right click and by convention, users hold the Command Key down and then click with the poor crippled mouse they use.

They have had right clicks, and more, for over a decade:

https://support.apple.com/en-gb/HT204895

https://en.wikipedia.org/wiki/Magic_Mouse

« Last Edit: August 17, 2020, 02:56:04 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.0
macOS 10.13.6: Lazarus 2.0.10 (64 bit Cocoa)
Ubuntu 18.04.3: Lazarus 2.0.10 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.10 (64 bit on VBox)

 

TinyPortal © 2005-2018