MouseUp event handler does not detect the pressed mouse button lazarus / 31-LCL ---------------------------------------------------------------------- simsee · 2023-11-20 14:30 As can be deduced from the following code, while the MouseDown event handler detects the pressed mouse button and places it in the Shift set, the same thing does not happen with MouseUp. Is this correct and expected behavior? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type   { TForm1 }   TForm1 = class(TForm)    procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);    procedure FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);  private    procedure WriteShift(Shift: TShiftState);  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.WriteShift(Shift: TShiftState);var  ShiftStateEnum : TShiftStateEnum;begin  for ShiftStateEnum in TShiftStateEnum do    if ShiftStateEnum in Shift then      writeln(ShiftStateEnum);  writeln;end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin  writeln('FormMouseDown');  WriteShift(Shift);end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);begin  writeln('FormMouseUp');  WriteShift(Shift);end; end. ---------------------------------------------------------------------- wp · 2023-11-20 14:45 This is the same as in Delphi. The logics behind it probably is: the ShiftState represents the set of the pressed buttons. When the left button is pressed it is included in the Shift set because it is down. When it is released it is no longer held down and therefore removed from Shift. But note: You can always get the button which is pressed or released from the Button argument of the event handler. ---------------------------------------------------------------------- simsee · 2023-11-20 14:49 Thanks WP. So the State parameter in MouseUP carries no information and is therefore useless. ---------------------------------------------------------------------- wp · 2023-11-20 14:57 No. You still can have the CTRL, SHIFT, ALT keys down... But yes, it is useless regarding the mouse button. ---------------------------------------------------------------------- Josh · 2023-11-20 14:59 placing 2 labels on form, then using code below, the shift is detected in mouse up and mousedown... Code: [Select]procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin  if ssShift in Shift then label1.caption:='MD: Shift' else label1.caption:='MD:'; end; procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin   If ssShift in Shift then label2.caption:='MU: Shift' else label2.caption:='MU'; end; ---------------------------------------------------------------------- jamie · 2023-11-21 00:04 Works for me. Hold the LEFT mouse button down and click the right mouse button. The ssLEFT is reported, because that is the shift state. Same the other way, hold the Right mouse button down and click the left mouse button. That reports ssRight mouse button. So this means the buttons on the mouse that are being held down while another mouse button is clicked reports the mouse button being held down.  If you want to know the actual clicked mouse button, use the BUTTON parameter and from there, use a case statement to check the shift states.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Case Butotn of  mbMiddle:If ssLeft in state Then... else if ssright in State then ...   same for the ither mouse buttons.