mouse_click.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import roslib; roslib.load_manifest('world_intersect')
00003 import rospy
00004 from std_msgs.msg import Empty
00005 
00006 import Xlib
00007 import Xlib.display
00008 from Xlib.protocol import rq
00009 from Xlib import X
00010 from Xlib.ext import record
00011 
00012 class MouseClick:
00013         def __init__(self):
00014                 #disp = Xlib.display.Display()
00015                 self.disp = Xlib.display.Display(':0')
00016                 self.click_pub = rospy.Publisher('click', Empty)
00017 
00018         def mouse_cb(self, evt):
00019                 data = evt.data
00020                 while len(data):
00021                         event, data = rq.EventField(None).parse_binary_value(data, self.disp.display, None, None)
00022                         if event.type == X.ButtonRelease:
00023                                 self.click_pub.publish()        
00024 
00025         def start(self):
00026                 ctx = self.disp.record_create_context(
00027                         0,
00028                         [record.AllClients],
00029                         [{
00030                                         'core_requests': (0, 0),
00031                                         'core_replies': (0, 0),
00032                                         'ext_requests': (0, 0, 0, 0),
00033                                         'ext_replies': (0, 0, 0, 0),
00034                                         'delivered_events': (0, 0),
00035                                         'device_events': (X.ButtonPressMask, X.ButtonReleaseMask),
00036                                         'errors': (0, 0),
00037                                         'client_started': False,
00038                                         'client_died': False,
00039                 }])
00040                 root = self.disp.screen().root
00041                 root.grab_pointer(True, X.ButtonPressMask | X.ButtonReleaseMask, X.GrabModeAsync, X.GrabModeAsync, 0, 0, X.CurrentTime)
00042                 self.disp.record_enable_context(ctx, self.mouse_cb)
00043 
00044 if __name__ == '__main__':
00045         rospy.init_node('mouse_click')
00046         mc = MouseClick()
00047         mc.start()


world_intersect
Author(s): Daniel Lazewatsky
autogenerated on Mon Oct 6 2014 10:19:35