GetKeyState在firemonkey [英] GetKeyState in firemonkey
本文介绍了GetKeyState在firemonkey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在VCL(Delphi 2010)中,我使用这个函数来检查控制键是否被按下:
function IsControlKeyPressed:Boolean;
begin
结果:= GetKeyState(VK_CONTROL)< 0;
结束
GetKeyState是Windows库中的函数,我不想将其包含在我的项目中。 >
如何在XE3中为firemonkey应用程序按控制键或Shift键?
解决方案
如果对其他人有帮助,这是我的单位:
unit uUtils;
接口
使用
{$ IFDEF MSWINDOWS}
Winapi.Windows;
{$ ELSE}
Macapi.AppKit;
{$ ENDIF}
函数IsControlKeyPressed:Boolean;
函数IsShiftKeyPressed:Boolean;
实现
函数IsControlKeyPressed:Boolean;
begin
{$ IFDEF MSWINDOWS}
结果:= GetKeyState(VK_CONTROL)< 0;
{$ ELSE}
结果:= NSControlKeyMask和TNSEvent.OCClass.modifierFlags = NSControlKeyMask;
{$ ENDIF}
end;
函数IsShiftKeyPressed:Boolean;
begin
{$ IFDEF MSWINDOWS}
结果:= GetKeyState(VK_SHIFT)< 0;
{$ ELSE}
结果:= NSShiftKeyMask和TNSEvent.OCClass.modifierFlags = NSShiftKeyMask;
{$ ENDIF}
end;
结束。
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.
这篇关于GetKeyState在firemonkey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文