Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 17 Nov 2019, 07:08
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Detecting mouse clicks... Any help or ideas?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [10 Posts]  
Author Message
sc0ttman


Joined: 16 Sep 2009
Posts: 2742
Location: UK

PostPosted: Thu 29 Dec 2011, 11:36    Post subject:  Detecting mouse clicks... Any help or ideas?
Subject description: (using xdotool, shell, or any other lightweight or 'built in' method...
 

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:
xdotool search --name "VLC" behave %@ mouse-click exec 'myscript'

However, this does work, but is not what I need:

Code:
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 Sad
_______________________________________________________________

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:
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
}

_________________
Pkg, mdsh, Woofy, Akita, VLC-GTK, Search

Last edited by sc0ttman on Mon 02 Jan 2012, 15:06; edited 2 times in total
Back to top
View user's profile Send private message 
puppyluvr


Joined: 06 Jan 2008
Posts: 3503
Location: Chickasha Oklahoma

PostPosted: Thu 29 Dec 2011, 14:00    Post subject:  

Very Happy 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...
Back to top
View user's profile Send private message Visit poster's website 
seaside

Joined: 11 Apr 2007
Posts: 935

PostPosted: Fri 30 Dec 2011, 17:34    Post subject:  

sc0ttman,

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

maybe mouseup or mousedown?

Regards,
s
Back to top
View user's profile Send private message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2742
Location: UK

PostPosted: Fri 30 Dec 2011, 21:01    Post subject:  

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:
# 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'

_________________
Pkg, mdsh, Woofy, Akita, VLC-GTK, Search
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4871
Location: Blue Springs, MO

PostPosted: Fri 30 Dec 2011, 22:04    Post subject:  

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 github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
sc0ttman


Joined: 16 Sep 2009
Posts: 2742
Location: UK

PostPosted: Sat 31 Dec 2011, 09:52    Post subject:  

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:
# 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:
# CURX=`getcurpos | cut -f1 -d' '`
# CURY=`getcurpos | cut -f2 -d' '`

_________________
Pkg, mdsh, Woofy, Akita, VLC-GTK, Search

Last edited by sc0ttman on Sat 31 Dec 2011, 11:25; edited 2 times in total
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1742

PostPosted: Sat 31 Dec 2011, 10:41    Post subject:  

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/viewtopic.php?t=69647&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:
 xwininfo -name rxvt



this monitors the events taking place
Code:
 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
Back to top
View user's profile Send private message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2742
Location: UK

PostPosted: Sat 31 Dec 2011, 10:58    Post subject:  

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 Wink

_________________
Pkg, mdsh, Woofy, Akita, VLC-GTK, Search
Back to top
View user's profile Send private message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2742
Location: UK

PostPosted: Sat 31 Dec 2011, 12:25    Post subject:  

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:
#!/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:
while [ 1 = 1 ];do
VAR=''
[ "$(mouse_click_detector)" = true ] && VAR=`myscript`
[ "$VAR" = true ] && dostuff || sleep 0.5
done

_________________
Pkg, mdsh, Woofy, Akita, VLC-GTK, Search
Back to top
View user's profile Send private message 
sc0ttman


Joined: 16 Sep 2009
Posts: 2742
Location: UK

PostPosted: Sat 31 Dec 2011, 12:50    Post subject:  

Mouse Events: http://myfreebsd.homeunix.net/freebsd/mouse_events_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...

_________________
Pkg, mdsh, Woofy, Akita, VLC-GTK, Search
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [10 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0523s ][ Queries: 11 (0.0058s) ][ GZIP on ]