function TViewPlayWorld.Press(const Event: TInputPressRelease): Boolean;
begin
Result := inherited;
if Event.MouseButton = TCastleMouseButton.buttonLeft then
begin
...
end;
end;
However, sometimes Event.MouseButton has the value TCastleMouseButton.buttonLeft even though I did not press the mouse button at all.
Update :
I noticed that when rotating the mouse scroll wheel, the mouse button event reports the value buttonLeft.
Exactly, check EventType first. Please consult our examples, they all show a simple way of doing it, by IsMouseButton, like
function TViewPlay.Press(const Event: TInputPressRelease): Boolean;
begin
Result := inherited;
if Result then Exit; // allow the ancestor to handle keys
if Event.IsMouseButton(buttonLeft) then
begin
// .. do something
Exit(true); // handled
end;
end;
IsMouseButton internally checks EventType before checking MouseButton.
Also, just buttonLeft is good, no need for TCastleMouseButton.buttonLeft. We don’t use “scoped enums” for CGE enums, at least now (for historical reasons).