Recent

Author Topic: How do I read mouse button state in a MouseMove eventt?  (Read 881 times)

741

  • New Member
  • *
  • Posts: 27
How do I read mouse button state in a MouseMove eventt?
« on: August 01, 2025, 09:43:09 pm »
The MouseMove event appears to only get called if no buttons are pressed.

I am considering setting a global variable when the button is pressed, but that feels like bad style.

procedure TfrmMain.pbxGridMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
   aButton: Word;
begin
  //Decide which cell we are in
  cellX := X DIV gridSizX;
  cellY := (pbxFieldPro.Height - Y) DIV gridSizY; //Want 'Y' "going upwards"
  sbrImagZ.Panels[4].Text := Format('pbxField: (x:%d, y:%d) --> Cell = (%d, %d)', [X, Y, cellX, cellY]);

//PROBLEM: If mouse button is down we do not see the move event[?]. On release we see the move, but then the button is zero

  aButton := GetMouseButtons;
  sbrImagZ.Panels[0].Text := Format('Button = $%2X', [aButton]);

  if MouseLeftButton = GetMouseButtons then
  begin
//##############Never get here UNTIL button released#####################
     pbxFieldProMouseDown(pbxFieldPro, mbLeft, Shift, X, Y);
  end;//if
end;//pbxGridMouseMove

jamie

  • Hero Member
  • *****
  • Posts: 7763
Re: How do I read mouse button state in a MouseMove eventt?
« Reply #1 on: August 02, 2025, 12:24:40 am »
Mouse Move works for me no matter what button I hold down, it still gets called.

What widget are you on?

and btw..

is 741 anything to do with the LM741 op-amp ? :o

Jamie
The only true wisdom is knowing you know nothing

741

  • New Member
  • *
  • Posts: 27
Re: How do I read mouse button state in a MouseMove eventt?
« Reply #2 on: August 02, 2025, 12:06:59 pm »
Hi

"What widget are you on?".
Not sure how to find the answer to that (!) I will admit I am not a regular Lazarus user (I used to code with Delphi lots some years ago though).

Yes, the famous 741 op-amp  ;D


Please can you post your code where MouseMove is seen, even when the left button is continually down?

Regards
Stephen

Sieben

  • Sr. Member
  • ****
  • Posts: 390
Re: How do I read mouse button state in a MouseMove eventt?
« Reply #3 on: August 02, 2025, 12:25:10 pm »
With mouse events the Shift parameter also holds information about the mouse buttons: https://www.freepascal.org/docs-html/rtl/classes/tshiftstate.html
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

741

  • New Member
  • *
  • Posts: 27
Re: How do I read mouse button state in a MouseMove eventt?
« Reply #4 on: August 02, 2025, 12:35:44 pm »
Very interesting - thank you  :)

 

TinyPortal © 2005-2018