* * *

Author Topic: How to adapt GetKeyState(VK_CONTROL) to macOS  (Read 670 times)

Alextp

  • Hero Member
  • *****
  • Posts: 595
    • UVviewsoft
How to adapt GetKeyState(VK_CONTROL) to macOS
« on: January 13, 2018, 04:25:38 pm »
ATSynEdit uses Ctrl+dragdrop to _copy_ text on dragdrop, if Ctrl is pressed.
"Ctrl pressed" is get not from Shift parametr, but from func:

Code: Pascal  [Select]
  1. function IsPressedCtrl: boolean;
  2. begin
  3.   Result:= GetKeyState(VK_CONTROL)<0;
  4. end;
  5.  

Now on macOS it don't work, ie Ctrl press not detected [Carbon, macOS 10.8].
How to adapt this func to use COMMAND key on macOS?
in any way i need COMMAND key.

Blaazen

  • Hero Member
  • *****
  • Posts: 2510
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to adapt GetKeyState(VK_CONTROL) to macOS
« Reply #1 on: January 13, 2018, 04:58:02 pm »
Use function GetKeyShiftState and test it for ssModifier instead of ssCtrl:
Code: Pascal  [Select]
  1. if ssModifier in GetKeyShiftState then ...
Lazarus 1.9.0 r57500 FPC 3.0.4 x86_64-linux-qt Chakra, Qt 4.8.7, Plasma 5.11.4
Lazarus 1.8.0 r56594 FPC 3.0.4 i386-win32-win32/win64 Wine 3.2

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Thaddy

  • Hero Member
  • *****
  • Posts: 5795
Re: How to adapt GetKeyState(VK_CONTROL) to macOS
« Reply #2 on: January 13, 2018, 05:00:13 pm »
That fails on alt- then...and shift... (I have to start up my mini first, untested)
« Last Edit: January 13, 2018, 05:16:36 pm by Thaddy »
recommends {$macro on}{$define Silly:=ObjFpc}

Blaazen

  • Hero Member
  • *****
  • Posts: 2510
  • POKE 54296,15
    • Eye-Candy Controls
Re: How to adapt GetKeyState(VK_CONTROL) to macOS
« Reply #3 on: January 13, 2018, 05:05:16 pm »
ssModifier is defined as
Code: Pascal  [Select]
  1. ssModifier = {$if defined(darwin) or defined(macos) or defined(iphonesim)} ssMeta {$else} ssCtrl {$endif};
so command key is ssMeta on MacOS.

Now I see that GetKeyShiftState calls GetKeyState.
Lazarus 1.9.0 r57500 FPC 3.0.4 x86_64-linux-qt Chakra, Qt 4.8.7, Plasma 5.11.4
Lazarus 1.8.0 r56594 FPC 3.0.4 i386-win32-win32/win64 Wine 3.2

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

GetMem

  • Hero Member
  • *****
  • Posts: 2930
Re: How to adapt GetKeyState(VK_CONTROL) to macOS
« Reply #4 on: January 13, 2018, 05:05:45 pm »
This works perfectly fine on macOS Sierra, Lazarus Trunk/FPC 3.0.4:
Code: Pascal  [Select]
  1. uses lclintf, lcltype;
  2.  
  3. procedure TForm1.Timer1Timer(Sender: TObject);
  4. begin
  5.   if GetKeyState(VK_CONTROL)<0 then
  6.     Caption := 'ctrl down'
  7.   else
  8.     Caption := 'ctrl up';
  9. end;
  10.  

Alextp

  • Hero Member
  • *****
  • Posts: 595
    • UVviewsoft
Re: How to adapt GetKeyState(VK_CONTROL) to macOS
« Reply #5 on: January 13, 2018, 05:39:04 pm »
@GetMem
I tested on macOS 10.8 on VMWare. hm...

Thanks, will use ssModifier.

Alextp

  • Hero Member
  • *****
  • Posts: 595
    • UVviewsoft
Re: How to adapt GetKeyState(VK_CONTROL) to macOS
« Reply #6 on: January 13, 2018, 05:50:50 pm »
Changed func like this
Code: Pascal  [Select]
  1. function IsPressedCtrl: boolean;
  2. begin
  3.   {$ifdef darwin}
  4.   //on macOS use Command-key instead of Ctrl
  5.   Result:=
  6.     (GetKeyState(VK_LWIN)<0) or
  7.     (GetKeyState(VK_RWIN)<0);
  8.   {$else}
  9.   Result:= GetKeyState(VK_CONTROL)<0;
  10.   {$endif}
  11. end;
  12.  

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus