Detecting mouse clicks... Any help or ideas?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

Detecting mouse clicks... Any help or ideas?

#1 Post by sc0ttman »

UPDATE: Most of this is solved, so I changed the title...

The only thing left to do is DETECT mouse clicks...

How do I use xdotool (or other methods?) to detect a mouse-click?

This should work, but it doesn't:

Code: Select all

xdotool search --name "VLC" behave %@ mouse-click exec 'myscript'
However, this does work, but is not what I need:

Code: Select all

xdotool search --name "VLC" behave %@ mouse-enter exec 'myscript'
I'm using xdotool version 2.20101012.304.. EDIT: I also just compiled and tried xdotool version 2.20110530.1...
Same result for both version - 'mouse-click' does not work, but 'mouse-enter' and 'mouse-leave' DO work :(
_______________________________________________________________

Older post:

I'd like to add a right click menu to VLC video playback windows, by;

1. detecting if a right click is within the VLC window in question,
2. then loading a gtkdialog GUI with <menu> stuff...

I already have stuff in place to detect the window id needed..
It could almost certainly be simplified and improved...

Code: Select all

get_wids () {
	#BK vlc 1.1.5 does not display a window with "XVideo output" in title...
	#BK note, default video output setting is saved in /root/.config/vlc/vlcrc, exs: vout=xcb_glx, vout=xcb_x11, vout=xcb_xv, vout=vout_sdl
	for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #BK delay is needed.
	do
	 wid=`xdotool search --name "(XVideo output)"`  # get the vlc playback windowid specifically
	 [ "$wid" = "" ] && wid=`xdotool search --name "VLC (hardware YUV SDL output)"`  #BK output: SDL
	 [ "$wid" = "" ] && wid=`xdotool search --name "VLC media player"`  #BK outputs: XVideo, X11, GLX
	 [ "$wid" != "" ] && break
	 CNT=$(($CNT+1))
	 sleep 0.25
	done
	vlcwid=`xdotool search --name "vlc"`  # look for the vlc window(s)
	vlcgtkwid=`xdotool search --name "vlc-gtk"`
	guiwid=`xdotool search --name "VLC Controls"`
	# start double-checking for wids
	for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # delay is needed
	do 
		if [ "$wid" = "" ] || [ "$vlcwid" = "" ];then # dont include guiwid here, it wont be created on first call
			wid=`xdotool search --name "(XVideo output)"`
			 [ "$wid" = "" ] && wid=`xdotool search --name "VLC (hardware YUV SDL output)"`  #BK output: SDL
			 [ "$wid" = "" ] && wid=`xdotool search --name "VLC media player"`  #BK outputs: XVideo, X11, GLX
			vlcwid=`xdotool search --name "vlc"`
			vlcgtkwid=`xdotool search --name "vlc-gtk"`
			guiwid=`xdotool search --name "VLC Controls"`
			sleep 0.25
		else
			break
		fi
	done
}
Last edited by sc0ttman on Mon 02 Jan 2012, 19:06, edited 2 times in total.
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
puppyluvr
Posts: 3470
Joined: Sun 06 Jan 2008, 23:14
Location: Chickasha Oklahoma
Contact:

#2 Post by puppyluvr »

:D Hello,
getcurpos
will return cursor location..
Maybe something in
grep "$MOUSE:" /proc/interrupts
to detect clicks???
Close the Windows, and open your eyes, to a whole new world
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!

Puppy since 2.15CE...

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#3 Post by seaside »

sc0ttman,

Just a total shot in the dark and I'm not anywhere to test...

maybe mouseup or mousedown?

Regards,
s

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#4 Post by sc0ttman »

seaside wrote:sc0ttman,

Just a total shot in the dark and I'm not anywhere to test...

maybe mouseup or mousedown?

Regards,
s
Unfortunately not...

Code: Select all

# xdotool search --name "VLC" behave %@ mouse-down exec 'woofy'
Unknown event 'mouse-down'
# xdotool search --name "VLC" behave %@ mouse-up exec 'woofy'
Unknown event 'mouse-up'
# xdotool search --name "VLC" behave %@ mouseup exec 'woofy'
Unknown event 'mouseup'
# xdotool search --name "VLC" behave %@ mousedown exec 'woofy'
Unknown event 'mousedown'
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#5 Post by technosaurus »

My laptop just died on me, so I can't test, but xwininfo to get vlc location and geometry and some Keylogger/getcurpos to hack for mouse clicks. (bonus with a Keylogger, you can have hotkeys)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#6 Post by sc0ttman »

technosaurus wrote:My laptop just died on me, so I can't test, but xwininfo to get vlc location and geometry and some Keylogger/getcurpos to hack for mouse clicks. (bonus with a Keylogger, you can have hotkeys)
Yet to tackle mouse clicks, but this is what I got so far:

Code: Select all

# XPOS=`xwininfo -name Transmission | grep geometry | cut -f4 -d' '| cut -f2 -d'+'`
# YPOS=`xwininfo -name Transmission | grep geometry | cut -f4 -d' '| cut -f3 -d'+'`
# WIDTH=`xwininfo -name Transmission | grep geometry | cut -f4 -d' '| cut -f1 -d'x'`
# HEIGHT=`xwininfo -name Transmission | grep geometry | cut -f4 -d' '| cut -f2 -d'x' | cut -f1 -d'+'`
# XPOSEND=$(($XPOS + $WIDTH))
# YPOSEND=$(($YPOS + $HEIGHT))
# CURX=50
# CURY=300
# echo "$XPOS+$WIDTH=$XPOSEND, $YPOS+$HEIGHT=$YPOSEND, $CURX and $CURY"
21+447=468, 0+310=310, 50 and 300
# [ $CURX -gt $XPOS ] && [ $CURX -lt $XPOSEND ] && [ $CURY -gt $YPOS ] && [ $CURY -lt $YPOSEND ] && echo inside || echo outside
inside
# CURX=500
# [ $CURX -gt $XPOS ] && [ $CURX -lt $XPOSEND ] && [ $CURY -gt $YPOS ] && [ $CURY -lt $YPOSEND ] && echo inside || echo outside
outside
# CURX=100
# CURY=450
# [ $CURX -gt $XPOS ] && [ $CURX -lt $XPOSEND ] && [ $CURY -gt $YPOS ] && [ $CURY -lt $YPOSEND ] && echo inside || echo outside
outside
# CURY=250
# [ $CURX -gt $XPOS ] && [ $CURX -lt $XPOSEND ] && [ $CURY -gt $YPOS ] && [ $CURY -lt $YPOSEND ] && echo inside || echo outside
inside
Also can use this:

Code: Select all

# CURX=`getcurpos | cut -f1 -d' '`
# CURY=`getcurpos | cut -f2 -d' '`
Last edited by sc0ttman on Sat 31 Dec 2011, 15:25, edited 2 times in total.
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#7 Post by big_bass »

Hey sc0ttman

--------------------------------------------------------------------------
a different topic but this may interest you
well it uses mplayer but you could modify this frontend for VLC
and it calls gtk directly so events are allowed
also shows the power of BaCon
http://www.murga-linux.com/puppy/viewto ... 7&start=11
------------------------------------------------------------------------

now I will get to your question
here you replace the rxvt with your apps name its only so you can test
and get an idea what to expect

this gets your display info

Code: Select all

 xwininfo -name rxvt 

this monitors the events taking place

Code: Select all

 xev -name rxvt
*I had to compile xev I got it from the X11 sources
(I used slackware sources ) it works fine for me


oh I dont want to forget most of all have fun
these are the spices I can offer to your code soup
use any to your preferences or none at all its your soup

Joe

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#8 Post by sc0ttman »

thanks bigbass... I added xev to my system about 2 or 3 months ago.. then forgot about it! lol.. I will look into `xev -name`...

And thanks for the links as well, I'll have a look through the thread, see what I am missing out on ;)
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#9 Post by sc0ttman »

Damn.. so close.. Al I need is what I thought would be the easy part - detecting a mouse click.. I can verify if the mouse is within a given program window, I just need to monitor for mouse clicks and run my script when the mouse is clicked.. my script will do the rest..

I am using this:

Code: Select all

#!/bin/sh
# sc0ttman, 31/12/2011
XPOS='' YPOS='' WIDTH='' HEIGHT='' XPOSEND='' YPOSEND='' CURX='' CURY='' INSIDEPROG='' 
[ "$1" = "" ] && PROG="Transmission" || PROG="$1"
# get X and Y positions of $PROG
XPOS=`xwininfo -name "$PROG" | grep geometry | cut -f4 -d' '| cut -f2 -d'+'`
YPOS=`xwininfo -name "$PROG" | grep geometry | cut -f4 -d' '| cut -f3 -d'+'`
# get dimensions of $PROG window
WIDTH=`xwininfo -name "$PROG" | grep geometry | cut -f4 -d' '| cut -f1 -d'x'`
HEIGHT=`xwininfo -name "$PROG" | grep geometry | cut -f4 -d' '| cut -f2 -d'x' | cut -f1 -d'+'`
# get screen dimensions taken by $PROG
XPOSEND=$(($XPOS + $WIDTH))
YPOSEND=$(($YPOS + $HEIGHT))
# get current mouse position
CURX=`getcurpos | cut -f1 -d' '`
CURY=`getcurpos | cut -f2 -d' '`
#echo "$XPOS+$WIDTH=$XPOSEND, $YPOS+$HEIGHT=$YPOSEND, $CURX and $CURY"
# test if mouse cursor is inside $PROG
[ $CURX -gt $XPOS ] && [ $CURX -lt $XPOSEND ] && [ $CURY -gt $YPOS ] && [ $CURY -lt $YPOSEND ] && INSIDEPROG=true || INSIDEPROG=false
# do something here if $INSIDE_PROG is true
if [ "$INSIDEPROG" = true ];then
	echo true
else 
	echo false
fi
And I will do something like this (not real code, of course):

Code: Select all

while [ 1 = 1 ];do
VAR=''
[ "$(mouse_click_detector)" = true ] && VAR=`myscript`
[ "$VAR" = true ] && dostuff || sleep 0.5
done
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

User avatar
sc0ttman
Posts: 2812
Joined: Wed 16 Sep 2009, 05:44
Location: UK

#10 Post by sc0ttman »

Mouse Events: http://myfreebsd.homeunix.net/freebsd/m ... shell.html

Th above site seems to have to solved it,
but I'm too thick to apply (or even find) the relevant stuff..

EDIT:: The script seems to only register clicks in a terminal emulator window, not elsewhere, which is no good...
[b][url=https://bit.ly/2KjtxoD]Pkg[/url], [url=https://bit.ly/2U6dzxV]mdsh[/url], [url=https://bit.ly/2G49OE8]Woofy[/url], [url=http://goo.gl/bzBU1]Akita[/url], [url=http://goo.gl/SO5ug]VLC-GTK[/url], [url=https://tiny.cc/c2hnfz]Search[/url][/b]

Post Reply