Get mouse coordinates on the screen

jipicy Posted messages 40842 Registration date   Status Modérateur Last intervention   -  
jipicy Posted messages 40842 Registration date   Status Modérateur Last intervention   -
Hi everrrrrrrrrrry body,

I’m looking for a command (preferably in shell bash) that can return the mouse coordinates...

Let me explain.

I would like to retrieve the mouse coordinates on my desktop (in X environment) in order to use them to open a console (Eterm) with the appropriate coordinates (x,y position and width/height dimensions) as well as various parameters.

So I tried with "xev", but it's not ideal. In fact, I couldn’t get anything useful from it ;-((

So if you have any leads or a solution at all, I would be grateful.

Thank you in advance and have a great weekend.

--
Z'@+...che.
JP : Zen, my Nuggets ! ;-) Knowledge is only good when it is shared.

7 réponses

jipicy Posted messages 40842 Registration date   Status Modérateur Last intervention   4 898
 
Well, I've made some progress and I'll try to share my current state of advancement...

So I'll start with "xev", which, while very useful for the keyboard (key recognition), is a bit less so (unless it's just me who can't get the hang of it) when it comes to the mouse.

If launched without any parameters, it displays a window (50x50) that, when hovered over, effectively sends the mouse coordinates in real-time, clicks, etc... but only within that window!!!
You might ask, why not resize it, or even better, pass the size and position as parameters?
Well, I thought about it, but there’s still a significant border and the output is so verbose that you easily get lost in the results!!!

Additionally, I tried to capture the output in a text file (xev > fich.txt), but as mentioned above, it is way too verbose :-(
I also tried using the command "tee" through a pipe:
xev | tee fich.txt
to retrieve both the output on screen and in a file. Unfortunately, it doesn’t work!
Not only do I get no output on the screen, but the file remains desperately empty!!! ;-(((

If anyone knows why… please let me know.

Since I was getting nowhere with "xev", I turned to the command "import" from the excellent suite of tools from "Imagemagick".

I thought I had found the solution, but there’s a catch!

First, let me explain my manipulations and my "machines".

I launch a console "Eterm" (as simple as it gets, with just a predefined size and position):
Eterm -g 100x10+95+10&
Then I run the command "xwininfo" to retrieve the information related to this window (id, length, height, etc...):
xwininfo xwininfo: Please select the window about which you would like information by clicking the mouse in that window. xwininfo: Window id: 0x3200046 "jp@MDK: /home/jp" Absolute upper-left X: 98 Absolute upper-left Y: 39 Relative upper-left X: 0 Relative upper-left Y: 0 Width: 624 Height: 161 Depth: 24 Visual Class: TrueColor Border width: 0 Class: InputOutput Colormap: 0x20 (installed) Bit Gravity State: ForgetGravity Window Gravity State: NorthWestGravity Backing Store State: NotUseful Save Under State: no Map State: IsViewable Override Redirect State: no Corners: +98+39 -302+39 -302-568 +98-568 -geometry 100x10+95+10 
So far, no problems, although you might say that the size and geometry differ somewhat!!! ;-\
Well, you’re not wrong, that’s exactly where the "catch" lies!!!

Nevertheless, I then run the "machine" that I absolutely know how to use, which allows me to recover the coordinates (or so I thought):
import -verbose /dev/null /dev/null PS 631x193 1024x768+95+13 DirectClass 0.000u 0:01 /dev/null PS 631x193 1024x768+95+13 DirectClass 0.210u 0:01
which indeed returns (within a few pixels) the coordinates of the axes (+95+13) as well as those of the size (631x193) (the difference being due to the window decoration style under KDE).

I was saying that this is where the "catch" lies.
I cannot determine how the "-g" parameter (geometry) of Eterm is expressed, of which here’s an excerpt from the "man":
-g geom, --geometry geom Window geometry as Width x Height+X coord+Y coord, i.e 100x200+0+100
that same one returned by the "wininfo" command (-geometry 100x10+95+10), compared to the size expressed by "wininfo":
Width: 624 Height: 161
and the "import" command:
/dev/null PS 631x193 1024x768+95+13 DirectClass 0.000u 0:01

???

I don't know if I was clear, but if any kind soul could try to explain to me what mathematical function (that has never been my strong suit ;-( ) can solve this equation (if one exists... of course).

Thank you for taking the time to read this and thanks to those who will try to help me.

Have a great end of the weekend everyone.

--
See you...che.
JP: Zen, my Nuggets! ;-) Knowledge is only good when shared.
0
jipicy Posted messages 40842 Registration date   Status Modérateur Last intervention   4 898
 
Re- everyone,

Well, here it is ;-))))

I have actually found a solution to my problem.

So to summarize, actually "Eterm" does not use the "pixel" to define the size (width/height) of the window like other applications do, but like on the good old terminals (VT100), it uses the number of "columns" and "lines".

This explains my riddle in the previous post, namely the relationship between:

Width: 624
Height: 161

and
-geometry 100x10

which thus boils down to:

100 columns
and
10 lines

The ratio between the width and the number of columns is therefore:

 width (624) --------------------- = 6 (rounded) number of columns (100)


same for the height and the number of lines:
 height (161) -------------------- = 16 (rounded) number of lines (10)


So deducing for my issue, I just need to divide my width by 6 and the height by 14 (that’s the closest result from many tests I’ve performed), and I get the expected effect for my moulinette ;-)))

Well, I suppose there must be a more academic way to calculate the width/height/columns/lines ratio, so if there are any experts around... thank you in advance.

Good evening to all of you.

--
See you...che.
JP : Zen, my Nuggets ! ;-) Knowledge is only good when shared.
0
Phiphi57 Posted messages 789 Registration date   Status Contributeur Last intervention   295
 
Hi,

I don't know if this can help, but I guess there's another unknown in your problem: the font size used... right?
With a smaller font, you should have more lines and columns on the same 624x161...

Phiphi
0
Phiphi57 Posted messages 789 Registration date   Status Contributeur Last intervention   295
 
Hi,

with a bit of Google, it seems there is a "mouse-pixel-position" function related to Emacs (or XEmacs)
http://www.gnu.org/

maybe you could manage to use it??
I hope it can help a bit...

Phiphi
0
jipicy Posted messages 40842 Registration date   Status Modérateur Last intervention   4 898
 
Hi Phiphi,

Thank you for your interest.

Indeed, it’s a (the font size) possibility that I had thought of too (actually I had initially thought of considering the resolution) but I wasn't quite sure how to interconnect everything (as I mentioned earlier, math and I ... ;-[).

The link does indeed seem to talk about the mouse position, but it seems to me within the Emacs window itself, doesn’t it? At least, that’s what I understood (my English being somewhat basic).

Anyway, thanks again for your posts, but I will probably leave it at that (unless a kind soul writes out the solution for me), and with what I’ve “produced”, it suits me perfectly for the use I wanted, namely to draw a parallelogram anywhere on the desktop and open an Eterm with the required dimensions and predefined options (only the text color is passed as a parameter).

There you go, thanks again.

;-))
--
Z'@+...che.
JP: Zen, my Nuggets! ;-) Knowledge is only good if it's shared.
0
jipicy Posted messages 40842 Registration date   Status Modérateur Last intervention   4 898
 
I had forgotten just in case you might be interested in my nonsense ;-))
#! /bin/bash ## script.sh ## Usage : sh script.sh [parameter] ## parameter being a color "black-red-green-yellow-blue-magenta-cyan-white" # Retrieval into a variable of the values with the "import" command recup="$(import -verbose /dev/null)" # Sorting the obtained values coord="$(echo $recup | sed -e 's/D.*//;s/[^0-9x+]//g;s/1024x768/ /g;s/[+x]/ /g')" # Sending the retrieved values to a temporary file in the form of a list for i in $(echo $coord) do echo $i >> fich.tmp done # Retrieving each value into a variable i=1 for line in `cat fich.tmp` do eval V$i="$line" i=$(expr $i + 1) done # Defining the final variables L="$(expr $V1 / 6)" H="$(expr $V2 / 14)" x="$V3" y="$V4" # The command and its parameters Eterm -O0x --buttonbar 0 --scrollbar 0 --app-cursor -f "${1:-white}" -g "$L"x"$H"+"$x"+"$y"& # Deleting the temporary file rm -f fich.tmp exit 0
Have fun ;-))
--
Z'@+...che.
JP: Zen, my Nuggets ! ;-) Knowledge is only good if it is shared.
0
Mr Micoz
 
The "super macro" software allows you (among other things) to know the position of your cursor.
In the standard window, you select "Mouse Movement"
a window opens, asking you if you want to activate the capture, press Alt+c.
There you can see the cursor coordinates displayed in this window.
To freeze these coordinates, press ALT+C again.
That's it!
0
jipicy Posted messages 40842 Registration date   Status Modérateur Last intervention   4 898
 
Thank you, but do you have a link please, and are you sure it's for GNU/Linux? ;-))

--

Z'@+...che.
JP : Zen, my Nuggets ! ;-) Knowledge is only good when it's shared.
0