Recent

Author Topic: Detect mouse movement in FormMouseMove handler when pointer isover form controls  (Read 10587 times)

j111

  • New member
  • *
  • Posts: 8
Hello.

I need to detect mouse movement in FormMouseMove event for all form globally even mouse pointer is over form controls.
For keyboard event it is posible by using KeyPreview property of the form.

What should i do to catch mouse events globally?

KpjComp

  • Hero Member
  • *****
  • Posts: 680
mouse.CursorPos

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
mouse.CursorPos
That goes along with a TTimer or thread then.

KpjComp

  • Hero Member
  • *****
  • Posts: 680
That goes along with a TTimer or thread then.

TTimer should be fine,  Thread probably not a good idea.

edit: Unless you Syncrhonized within the Thread of course.
« Last Edit: May 03, 2012, 12:31:39 pm by KpjComp »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Application.UserInput (or similar)

search UserInput in ide/sourceeditor.pp (trunk / snapshot)

j111

  • New member
  • *
  • Posts: 8
So. The following code works great, but how to recognize only mouse events with Msg param of MyInput procedure.

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.AddOnUserInputHandler(@MyInput, True);
end;   

procedure TForm1.MyInput(Sender: TObject; Msg: Cardinal);
begin
    Form1.caption := IntToStr(Mouse.CursorPos.X)+':'+IntToStr(Mouse.CursorPos.Y);
end;   

KpjComp

  • Hero Member
  • *****
  • Posts: 680
if Msg = LM_MOUSEMOVE

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
On windows (windows only, use IFDEF) also WM_NCMOUSEMOVE

That is used, if the mouse is over the window border, or if the form itself has scrollbars, over the scrollbar....

To test, if it is over your windows
    if PtInRect(form.BoundsRect, Mouse.CursorPos) then

j111

  • New member
  • *
  • Posts: 8
With this code i hightligth controls when mouse move over them.
And main goal of the job is drop files from Dolphin to application.

Unfortunately OnDropFiles event disables mouse tracking and I cant visually indicate mouse movement while dragging selected files over form.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
You can use the PtInRect() method above for each valid control on form. Going through the array in a loop.

j111

  • New member
  • *
  • Posts: 8
Why user input frozen while dragging files on a form?

UserInputHandler continue working only after files was dropped.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
What about the OnDragOver event?

I haven't tested, it may only fire over the form, not over the children. But then

Code: [Select]
For i:- 0 to form.ControlCount-1 do form.controls[i].OnDragOver := form.OnDragOver;

j111

  • New member
  • *
  • Posts: 8
I'v tried.
As a result OnDragOver fires when Automatic drag mode is set ON and nothing happens while dragging files.

This is very similar to WM_DROPFILES message for windows - program can recognize that files were dragged only when files were droped.

On Windows in this case possible to use OLE drag and drop where are possibilities to control all proccess from start to drop.

But I dont known such mechanism on Linux.

 

TinyPortal © 2005-2018