Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetKeyState in firemonkey

In VCL (Delphi 2010) I used this function to check whether control key is pressed:

function IsControlKeyPressed: Boolean;
begin
  Result := GetKeyState(VK_CONTROL) < 0;
end;

GetKeyState is function in windows library that I do not want to include it into my project.

How can I check if control or shift key is pressed in XE3 for firemonkey application?

like image 218
AvgustinTomsic Avatar asked Jan 14 '23 23:01

AvgustinTomsic


1 Answers

If it helps for anyone else, this is my unit:

unit uUtils;

interface

uses
{$IFDEF MSWINDOWS}
  Winapi.Windows;
{$ELSE}
  Macapi.AppKit;
{$ENDIF}
function IsControlKeyPressed: Boolean;
function IsShiftKeyPressed: Boolean;

implementation

function IsControlKeyPressed: Boolean;
begin
{$IFDEF MSWINDOWS}
  Result := GetKeyState(VK_CONTROL) < 0;
{$ELSE}
  Result := NSControlKeyMask and TNSEvent.OCClass.modifierFlags = NSControlKeyMask;
{$ENDIF}
end;

function IsShiftKeyPressed: Boolean;
begin
{$IFDEF MSWINDOWS}
  Result := GetKeyState(VK_SHIFT) < 0;
{$ELSE}
  Result := NSShiftKeyMask and TNSEvent.OCClass.modifierFlags = NSShiftKeyMask;
{$ENDIF}
end;

end.
like image 190
AvgustinTomsic Avatar answered Jan 26 '23 01:01

AvgustinTomsic