Recent

Author Topic: OnMouseDown event  (Read 11490 times)

RW1962

  • New Member
  • *
  • Posts: 41
OnMouseDown event
« on: January 16, 2024, 11:57:27 am »
RichMemo has an event for OnMouseDown ...

procedure TCmdForm.MemoMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

But it doesn't allow ... var Handled: Boolean;

It seems like it should.

Rick

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: OnMouseDown event
« Reply #1 on: January 16, 2024, 01:37:59 pm »
Rick
Welcome to forum Rick!

It seems like it should.
Why you think that it seems to be missing?
It would be great if you add examples where it be needed, without not working etc...
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

RW1962

  • New Member
  • *
  • Posts: 41
Re: OnMouseDown event
« Reply #2 on: January 17, 2024, 04:04:44 pm »
The mouse triggers a Windows event, just like the keyboard will. If it had the HANDLED function then the Windows System would be told to ignore the mouse message. Moreover, that is how OnMouseWheel operates. It keeps from having crossed wires with the Windows System.

Rick

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: OnMouseDown event
« Reply #3 on: January 17, 2024, 04:56:15 pm »
Again, please add an example where HANDLED for a mouse-event is badly needed.
Just imagine it exists, so I do understand for what you are needing such.
I do usual "exit" that event whenever I want so there is no need for such.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

RW1962

  • New Member
  • *
  • Posts: 41
Re: OnMouseDown event
« Reply #4 on: January 18, 2024, 01:18:27 pm »
With this example mbExtra1 & mbExtra2 do not post the showmessage notice. This means that it does not process the function. However, mbRight does process ... my pop-up appears.

Nevertheless, the mouse button does activate the Windows System ... it does the PageUp & PageDown. This makes me think that Windows is overriding and suppressing my OnMouseDown operation.

It has also been sporadic. Sometimes the showmessage will post, and sometimes it won't do a PageUp or PageDown at all ... and no message.

Code: Pascal  [Select][+][-]
  1. procedure TCmdForm.btnPgBckClick(Sender: TObject);
  2. begin
  3.   with PageMemo do
  4.        try
  5.          Screen.Cursor:= crHourGlass;
  6.          PageMemo.SetFocus;  // must set focus
  7.          KeyInput.Press(VK_PRIOR);   // must be capital 'A' for 'a'
  8.          KeyInput.Up(VK_PRIOR);
  9.  
  10.        finally
  11.          PageMemo.SetFocus;
  12.          ReportPosition;
  13.          PrepareToolbar;
  14.          Screen.Cursor:= crDefault;
  15.        end;
  16. end;
  17.  
  18. procedure TCmdForm.btnPgNxtClick(Sender: TObject);
  19. var hit: longint;
  20. begin
  21.   with PageMemo do
  22.        try
  23.          Screen.Cursor:= crHourGlass;
  24.          hit:= PageMemo.SelStart;   // prep to work-around for being hung on a graphic
  25.          PageMemo.SetFocus;     // must set focus
  26.          KeyInput.Press(VK_NEXT);   // must be capital 'A' for 'a'
  27.          KeyInput.Up(VK_NEXT);
  28.  
  29.          if hit=PageMemo.SelStart then  // work-around for being hung on a graphic
  30.             begin
  31.             PageMemo.SelStart:= PageMemo.SelStart+1;
  32.             PageMemo.SetFocus;     // must set focus
  33.             KeyInput.Press(VK_NEXT);
  34.             KeyInput.Up(VK_NEXT);  // added
  35.             PageMemo.SelStart:= PageMemo.SelStart-1;  // *** maybe not ***
  36.             end;
  37.  
  38.          finally
  39.          PageMemo.SetFocus;
  40.          ReportPosition;
  41.          PrepareToolbar;
  42.          Screen.Cursor:= crDefault;
  43.        end;
  44. end;
  45.  
  46. // * CALLING ONMOUSEDOWN *
  47. procedure TCmdForm.MemoMouseDown(Sender: TObject; Button: TMouseButton;
  48.                                                           Shift: TShiftState; X, Y: Integer);
  49. var TempRTF: TRichMemo;
  50.     MemoSet: boolean;
  51. begin
  52.   MemoSet:= false;
  53.  
  54.   // assign active editor to TempRTF
  55.   if (PageMemoOn) and (not PagePassive) then // global editor flags
  56.      begin
  57.      TempRTF:= PageMemo;
  58.      MemoSet:= true;
  59.      end;
  60.   if SearchBoxOn then // global editor flag
  61.      begin
  62.      TempRTF:= SearchBox;
  63.      MemoSet:= true;
  64.      end;
  65.   if ReplaceBoxOn then // global editor flag
  66.      begin
  67.      TempRTF:= ReplaceBox;
  68.      MemoSet:= true;
  69.      end;
  70.  
  71.   if MemoSet then
  72.      begin
  73.      if not ((ssCtrl in Shift) or
  74.              (ssShift in Shift) or
  75.              (ssAlt in Shift)) then
  76.               begin
  77.               case Button of  // mbLeft, mbRight, mbMiddle, mbExtra1, mbExtra2
  78.                    mbRight: PopMenu.PopUp; // load popup menu  * IT WORKS *
  79.                    mbExtra1: begin
  80.                              showmessage('BACK'); // * NOTICE DOES NOT SHOW *
  81.                              btnPgBckClick(Self);
  82.                              end;
  83.                    mbExtra2: begin
  84.                              showmessage('NEXT'); // * NOTICE DOES NOT SHOW *
  85.                              btnPgNxtClick(Self);
  86.                              end;
  87.                    end; // end case
  88.               end; // end if not
  89.      end;  // if MemoSet
  90. end;
  91.  

RW1962

  • New Member
  • *
  • Posts: 41
Re: OnMouseDown event
« Reply #5 on: January 26, 2024, 04:06:42 pm »
@KodeZwerg

Why did you make me post my code? You haven't acted on it.

Meanwhile, I found a similar issue at... https://forum.lazarus.freepascal.org/index.php?topic=27316.0

They concluded that the "extra mouse buttons work in Windows only, currently"

I don't think that the extra mouse buttons work in Windows.

Rick

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: OnMouseDown event
« Reply #6 on: January 26, 2024, 05:24:30 pm »
@KodeZwerg

Why did you make me post my code? You haven't acted on it.
I was not able to follow your production code so I had nothing to say.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

bytebites

  • Hero Member
  • *****
  • Posts: 663
Re: OnMouseDown event
« Reply #7 on: January 26, 2024, 06:19:53 pm »
Code: Pascal  [Select][+][-]
  1.          KeyInput.Press(VK_PRIOR);   // must be capital 'A' for 'a'
  2.          KeyInput.Up(VK_PRIOR);

KeyInput.Press makes KeyInput.Down & KeyInput.Up
now you have key up without key down

RW1962

  • New Member
  • *
  • Posts: 41
Re: OnMouseDown event
« Reply #8 on: January 27, 2024, 12:55:48 pm »
@bytebites

Thanks for the input. I have taken the KeyInput.Up out of it. However, that had not impeded any actions. The problem, as I now perceive it, is that mbExtra1 and mbExtra2 are not implemented by the compiler (or maybe, FreePascal).

Yet what I cannot understand is why a mouse PgDn & PgUp had worked for years, and now it does not. That is why I thought it was interference by the Windows operating system.

Rick

Thaddy

  • Hero Member
  • *****
  • Posts: 15487
  • Censorship about opinions does not belong here.
Re: OnMouseDown event
« Reply #9 on: January 27, 2024, 01:05:12 pm »
Always use OnMouseUp when in doubt: it fires only once. OnMouseDown Keeps firing and is not usually what you mean or expect if you are a beginner.
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

RW1962

  • New Member
  • *
  • Posts: 41
Re: OnMouseDown event
« Reply #10 on: January 27, 2024, 08:35:52 pm »
@Thaddy

Thanks for helping.

I set it up for MouseUp, but it behaved the same as MouseDown. I have looked at the resources, and I am pretty sure that a functionality for the mbExtra1 & mbExtra2 has never been implemented. It only handles the first 3 buttons.

I had hoped to engineer my own functionality, but I can't, if I can't read the mouse. Maybe I will look into SendMessage to make it happen.

I have been attempting this because Windows has quit handling the 4 & 5 buttons. Other editors work with the buttons, but RichMemo does not.

All of this has developed within the last month. The buttons used to work. That's why I thought it was a Windows issue.

Rick

rvk

  • Hero Member
  • *****
  • Posts: 6288
Re: OnMouseDown event
« Reply #11 on: January 27, 2024, 11:09:01 pm »
I don't think that the extra mouse buttons work in Windows.
I just tested this on TRichMemo on Windows (with TRichMemo and TForm itself).
And it worked fine.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.RichMemo1MouseDown(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. begin
  4.   case Button of
  5.     mbLeft: TRichMemo(Sender).Lines.Add('Left');
  6.     mbRight: TRichMemo(Sender).Lines.Add('Right');
  7.     mbMiddle: TRichMemo(Sender).Lines.Add('Middle');
  8.     mbExtra1: TRichMemo(Sender).Lines.Add('Extra1');
  9.     mbExtra2: TRichMemo(Sender).Lines.Add('Extra2');
  10.   end;
  11. end;
  12.  
  13. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  14.   Shift: TShiftState; X, Y: Integer);
  15. begin
  16.   case Button of
  17.     mbLeft: RichMemo1.Lines.Add('form Left');
  18.     mbRight: RichMemo1.Lines.Add('form Right');
  19.     mbMiddle: RichMemo1.Lines.Add('form Middle');
  20.     mbExtra1: RichMemo1.Lines.Add('form Extra1');
  21.     mbExtra2: RichMemo1.Lines.Add('form Extra2');
  22.   end;
  23. end;

Quote
Right
Left
Extra1
Extra2
form Right
form Left
form Extra2
form Extra1

Let me test on Linux... firing up my hyper-V...
Yep.. same code and it works just fine.
Are you sure your mouse has extra1 and 2 and the mousedriver is picking them up?

Linux with TForm and TRichMemo:
Quote
form Right
form Left
form Extra1
form Extra2
Right
Left
Extra2
Extra1
Left

RW1962

  • New Member
  • *
  • Posts: 41
Re: OnMouseDown event
« Reply #12 on: January 27, 2024, 11:15:19 pm »
@rvk

I will try your windows functions to see how the act with my environment. Catch you tomorrow.

Rick

RW1962

  • New Member
  • *
  • Posts: 41
Re: OnMouseDown event
« Reply #13 on: January 28, 2024, 01:26:16 pm »
@rvk

The compiler would not accept:  TRichMemo(Sender).Lines.Add('Left');
I had to change it to: TempRTF.Lines.Add('Left');  // where is TempRTF: TRichMemo;

With that change it fired on the LEFT, MIDDLE, and RIGHT buttons.
But it would not fire on the Extra1 and Extra 2 buttons.

So I started a new project. Your code was all that I included.
I still had to change the TRichMemo(Sender) coding.
Once changed, it still behaved the same way.

I am operating on Lazarus IDE v2.0.10r63526,
but I also tried out v3.0 with the latest RichMemo,
and it behaved the same way.

I also use Windows 11.

Rick

rvk

  • Hero Member
  • *****
  • Posts: 6288
Re: OnMouseDown event
« Reply #14 on: January 28, 2024, 02:21:10 pm »
The compiler would not accept:  TRichMemo(Sender).Lines.Add('Left');
I had to change it to: TempRTF.Lines.Add('Left');  // where is TempRTF: TRichMemo;
Please note that the TRichMemo(Sender).Lines.Add only works in the TRichMemo.OnMouseDown
because there the Sender is a TRichMemo.

For the TForm.OnMouseDown you do need to use RichMemo1.Lines.Add directory with the form variable.

If the TRichMemo(Sender) doesn't work in TRichMemo.OnMouseDown then there is something seriously wrong with your installation.

With that change it fired on the LEFT, MIDDLE, and RIGHT buttons.
But it would not fire on the Extra1 and Extra 2 buttons.
So what happened if you use extra1 and extra2 on an empty part of the Form1?
That's what the tForm.OnMouseDown was for. To test if it works for just the Form in Lazarus.
If it doesn't then there must be something wrong with your mousedriver or you press something else than the extra1 and 2 button.

I am operating on Lazarus IDE v2.0.10r63526,
but I also tried out v3.0 with the latest RichMemo,
and it behaved the same way.

I also use Windows 11.
I used Windows 10 and Ubuntu 22.
But I just tried it in Windows 11 in Hyper-V and there it also just works.
I'm on Lazarus 3.99 (trunk) but that shouldn't mater unless they added something for the mouse later on.
Let me try on Laz3.0....Yep... works fine there too on both the TForm and TRichMemo. So it must be something on your end.

 

TinyPortal © 2005-2018