Recent

Author Topic: [Solved]Get mouse screen coordinates on Linux  (Read 856 times)

Ruptor

  • Full Member
  • ***
  • Posts: 184
[Solved]Get mouse screen coordinates on Linux
« on: March 07, 2019, 01:21:50 pm »
It seems like a simple task to me but I can't find any examples. I want to get the next two mouse click positions at anywhere on the screen. I know my form doesn't see the cursor but can I get system messages that I could decipher to get the position at a click? If there is an example please point me to it.
« Last Edit: March 07, 2019, 03:41:49 pm by Ruptor »

howardpc

  • Hero Member
  • *****
  • Posts: 3041
Re: Get mouse screen coordinates on Linux
« Reply #1 on: March 07, 2019, 02:07:32 pm »
Code: Pascal  [Select]
  1. uses Controls;
  2.  
  3. begin
  4.  ...
  5.  
  6.  with  Mouse.CursorPos do begin   // use CursorPos here (it is a TPoint)
  7.  ...
  8. end;
  9. end;
             

Ruptor

  • Full Member
  • ***
  • Posts: 184
Re: Get mouse screen coordinates on Linux
« Reply #2 on: March 07, 2019, 03:23:32 pm »
Thanks that is really simple. I can do what I need using a fudge by hitting return on my active window and collect the current cursor coordinates so I can get two points anywhere on the rest of the screen. It would be nice to be able to click the mouse to take the position but I think that might be too complicated for me since the active window is changed to where the cursor is and my window no longer sees the mouse.

440bx

  • Hero Member
  • *****
  • Posts: 945
Re: Get mouse screen coordinates on Linux
« Reply #3 on: March 07, 2019, 03:34:35 pm »
It would be nice to be able to click the mouse to take the position but I think that might be too complicated for me since the active window is changed to where the cursor is and my window no longer sees the mouse.
First, I need to disclaim that I don't know how to do what I'm going to suggest using the Lazarus framework but, you can have a thread that is mostly a loop executing GetCursorPos followed by Sleep(20) that sends the mouse coordinates to any window you want.   I said "mostly" because you probably should have a mechanism in place to end the thread once you no longer need it. 

If you'd rather not use a thread, you can also do it in a WM_TIMER message.  Personally, I prefer a thread because WM_TIMER messages can be erratic at times.

Maybe someone knowledgeable in using the framework can show you how it's done with a TIMER (it probably only takes a few lines of code.)  that is, if you are interested in such a solution.

HTH.
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.