[Lazarus] how to handle Shift=[ssCtrl]

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Thu Apr 2 14:39:59 CEST 2015


On 2015-04-02 12:54, Vojtěch Čihák wrote:
> if ssCtrl in Shift then ...
> 
> instead.
> 

It depends on how precise you want to be. Do you want that if statement
to execute even if Ctrl+Shift is pressed, or _only_ when Shift is pressed?

To get ONLY the specific modifier key, then you need to mask the result.
For example:

procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
  if (Shift*[ssShift,ssAlt,ssCtrl]) = [ssShift] then
    ShowMessage('really, only Shift was pressed');
  if Shift * [ssShift,ssAlt,ssCtrl] = [ssShift,ssCtrl] then
    ShowMessage('Only Shift+Ctrl was pressed');
  if ssShift in Shift then
    ShowMessage('Shift could have been pressed with ssAlt for example');
end;

The last if statement will trigger if you pressed Shift, or Shift+Ctrl,
or Shift+Alt, or Shift+Ctrl+Alt



Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/




More information about the Lazarus mailing list