我將TApplicationEvents.OnShortCutDelphi 11 Alexandria 中的事件與 Windows 10 中的 Delphi VCL 應用程式一起使用,例如:
procedure TformMain.ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
CodeSite.Send('TformMain.ApplicationEvents1ShortCut: Msg.CharCode', Msg.CharCode);
end;
不幸的是,這個事件甚至會在沒有按下任何修飾鍵時觸發,例如單獨按下“V”鍵或“B”鍵。當沒有按下修飾鍵時,如何退出此事件處理程式,例如:
procedure TformMain.ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
if NoModifierKeyPressed then EXIT;
...
end;
uj5u.com熱心網友回復:
您可以使用單元 Winapi.Windows 中的 GetKeyState 函式,以及 VK_CONTROL 或 VK_SHIFT 等虛擬鍵代碼。例如:
procedure TformMain.ApplicationEvents1ShortCut(var Msg: TWMKey; var Handled: Boolean);
begin
if (Msg.CharCode = Ord('V')) and (GetKeyState(VK_CONTROL) < 0) then
ShowMessage('Ctrl V was pressed');
end;
uj5u.com熱心網友回復:
考慮到@RemyLebeau 和@Andreas Rejbrand 的善意評論:
這對我有用:
function NoModifierKeyPressed: Boolean;
var
keys: TKeyboardState;
begin
GetKeyboardState(keys);
Result := (keys[VK_SHIFT] and $80 = 0) and (keys[VK_CONTROL] and $80 = 0) and (keys[VK_MENU] and $80 = 0);
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/357954.html
標籤:德尔福 键盘快捷键 delphi-11-alexandria
