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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With