Lazarus
Programming => LCL => Topic started by: j111 on May 03, 2012, 12:03:11 pm
-
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?
-
mouse.CursorPos
-
mouse.CursorPos
That goes along with a TTimer or thread then.
-
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.
-
Application.UserInput (or similar)
search UserInput in ide/sourceeditor.pp (trunk / snapshot)
-
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;
-
if Msg = LM_MOUSEMOVE
-
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
-
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.
-
You can use the PtInRect() method above for each valid control on form. Going through the array in a loop.
-
Why user input frozen while dragging files on a form?
UserInputHandler continue working only after files was dropped.
-
What about the OnDragOver event?
I haven't tested, it may only fire over the form, not over the children. But then
For i:- 0 to form.ControlCount-1 do form.controls[i].OnDragOver := form.OnDragOver;
-
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.