我有以下问题:我有一个应用程序,其中Ctrl键激活应用程序事件,并且一些用户使用RDP(远程访问)来使用该应用程序,问题是每次用户移动RDP时都会触发Ctrl键窗口或应用程序切换并返回到 RDP。
例如:
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Key = VK_CONTROL) then
ShowMessage('Ctrl Pressed');
end;
Run Code Online (Sandbox Code Playgroud)
我能够看到应用程序检测到 WM_KEYUP 消息并对其进行处理,最终触发带有参数 17 (Ctrl) 的 OnKeyUp 事件,模拟按下了 Ctrl 键。
我想知道是否有人知道这种行为是否是 Delphi/RDP 中的错误,以及是否有任何可能的解决方案。
看起来 Windows 发送按键来清除修改键状态。一种解决方案是确保您在采取行动之前先下跌。
CTRL 还用于切换桌面(除其他外),并且 CTRL-Win+箭头将在切换桌面时触发对话框,因此可能需要添加更多保护代码。
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TForm1 = class(TForm)
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ Private declarations }
CtrlDown : boolean;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Key = VK_CONTROL) then CtrlDown := true;
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Key = VK_CONTROL) and CtrlDown then
begin
ShowMessage('Ctrl Pressed');
CtrlDown := false;
end;
end;
end.
Run Code Online (Sandbox Code Playgroud)