Reputation: 331
With Delphi XE5, The SpaceBar Can not be trig when using FormKeyUp or KeyDown Method.
The Key value is 0 (instead of 32) if you it the spacebar. This was working on XE2.
procedure TfrmMaster.KeyDown(var Key: Word; var KeyChar: Char;
Shift: TShiftState);
begin
if Key = vkSpace then
begin
//custom handling
//if SomeTest then Exit; //don't do default handling
end;
inherited; //do default handling
end;
Type is Desktop HD Target is Windows 32/64 bits and Mac OS
Upvotes: 1
Views: 1407
Reputation: 125689
I can reproduce your problem in a new FMX HD application. A quick test shows that vkSpace
is never sent.
Events
tab in the Object Inspector, double-click the OnKeyDown
event, and add the following code:procedure TForm4.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin { if KeyChar = #32 then begin ShowMessage('Got space bar'); KeyChar := #0; end; } if Key = vkSpace then begin ShowMessage('Got space bar'); Key := 0; end else ShowMessage('Received key ' + IntToStr(Key)); end;
ShowMessage
executes, and indicates it Received key 0
.There's a simple workaround. I tested using the following code:
procedure TForm4.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin if KeyChar = #32 then begin ShowMessage('Got space bar'); // Display message KeyChar := #0; // Discard keystroke end; end;
To allow the default processing of the keystroke after the ShowMessage
call, simply remove the KeyChar := #0;
.
Upvotes: 1