Lazarus

Programming => General => Topic started by: Dan3468298 on August 04, 2020, 10:02:51 pm

Title: How do I test for MacOS COMMAND key down?
Post by: Dan3468298 on August 04, 2020, 10:02:51 pm
In KeyDown is the MacOS COMMAND key defined in a TShiftState?   I can't figure it out.  Any ideas?
Title: Re: How do I test for MacOS COMMAND key down?
Post by: jamie on August 04, 2020, 10:34:38 pm
Not sure on a mac but maybe the GetKeyState in the LCLIntf unit will do it ?

If you know the Virtual key code of the MAC key you can do this during a Keydown event..

Code: Pascal  [Select][+][-]
  1. If GetKeyState(VK_MACKEY?) < 0 THen its pressed..
  2.  

Like I said, I don't know what the key code would be...
Title: Re: How do I test for MacOS COMMAND key down?
Post by: dsiders on August 04, 2020, 10:59:34 pm
In KeyDown is the MacOS COMMAND key defined in a TShiftState?   I can't figure it out.  Any ideas?

I'm not a Mac user, so I don't know whether your version is based on Carbon or Cocoa.

For Carbon, the command key MK_COMMAND (sames as MK_APPLE) is mapped to VK_CONTROL. See lcl/interfaces/carbon/mackeycodes.inc and carbonproc.pp.

I don't see anything in the widgetset class for Cocoa.
Title: Re: How do I test for MacOS COMMAND key down?
Post by: skalogryz on August 04, 2020, 11:01:57 pm
In KeyDown is the MacOS COMMAND key defined in a TShiftState?   I can't figure it out.  Any ideas?
it's ssMeta
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  2. begin
  3.   if (ssMeta in Shift) then Caption:='Command is held'
  4.   else Caption :='not a command';
  5. end;
Title: Re: How do I test for MacOS COMMAND key down?
Post by: Dan3468298 on August 05, 2020, 12:42:17 am
Not sure on a mac but maybe the GetKeyState in the LCLIntf unit will do it ?

If you know the Virtual key code of the MAC key you can do this during a Keydown event..

Code: Pascal  [Select][+][-]
  1. If GetKeyState(VK_MACKEY?) < 0 THen its pressed..
  2.  

Like I said, I don't know what the key code would be...

KeyCode is 91 for the Command key.
Title: Re: How do I test for MacOS COMMAND key down?
Post by: Dan3468298 on August 05, 2020, 12:45:33 am
In KeyDown is the MacOS COMMAND key defined in a TShiftState?   I can't figure it out.  Any ideas?
it's ssMeta
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
  2. begin
  3.   if (ssMeta in Shift) then Caption:='Command is held'
  4.   else Caption :='not a command';
  5. end;

That worked.  Thanks!
Title: Re: How do I test for MacOS COMMAND key down?
Post by: VTwin on August 05, 2020, 03:01:18 am
I use this for cross-platform:

Code: Pascal  [Select][+][-]
  1.  // define standard menu command key as ssCmd
  2.   {$IFDEF DARWIN}
  3.   ssCmd = ssMeta; // Apple
  4.   {$ELSE}
  5.   ssCmd = ssCtrl; // Windows, Linux
  6.   {$ENDIF}
  7.  
Title: Re: How do I test for MacOS COMMAND key down?
Post by: Dan3468298 on August 05, 2020, 03:26:09 am
I use this for cross-platform:

Code: Pascal  [Select][+][-]
  1.  // define standard menu command key as ssCmd
  2.   {$IFDEF DARWIN}
  3.   ssCmd = ssMeta; // Apple
  4.   {$ELSE}
  5.   ssCmd = ssCtrl; // Windows, Linux
  6.   {$ENDIF}
  7.  

Thumbs up!  Thx
TinyPortal © 2005-2018