I have the following problem: I have an application in which the Ctrl key activates an application event, and some users use RDP (remote access) to use that application, the problem is that the Ctrl key is triggered every time the user moves the RDP window or application switch and return to RDP.
For example:
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Key = VK_CONTROL) then
ShowMessage('Ctrl Pressed');
end;
I was able to see that the application detects the WM_KEYUP message and treats it, which ends up triggering the OnKeyUp event with parameter 17 (Ctrl), simulating that the Ctrl key was pressed.
I would like to know if anyone has any idea if this behavior is a bug in Delphi / RDP and if it has any possible solution.
I'm using Delphi 10 Seatle
Looks like windows sends key ups to clear the modifier key state. One solution would to be to make sure you got a down before acting on the up.
Still CTRL is also used for switching desktop (amongst other things) and CTRL-Win+Arrow will trigger the dialog when switching desktops so might need to add more guard code.
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.
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