import time import zmq from pyPS4Controller.controller import Controller ctx = zmq.Context() socket = ctx.socket(zmq.PUB) ctrl_x = 1 ctrl_y = 1 class ps4if(Controller): def __init__(self, **kwargs): Controller.__init__(self, **kwargs) def on_R3_right(self, value): global ctrl_x ctrl_x = value socket.send_string(("X:%d Y:%d" % (ctrl_x, ctrl_y))) def on_R3_left(self, value): global ctrl_x ctrl_x = value socket.send_string(("X:%d Y:%d" % (ctrl_x, ctrl_y))) def on_R3_up(self, value): global ctrl_y ctrl_y = value socket.send_string(("X:%d Y:%d" % (ctrl_x, ctrl_y))) def on_R3_down(self, value): global ctrl_y ctrl_y = value socket.send_string(("X:%d Y:%d" % (ctrl_x, ctrl_y))) def on_R3_x_at_rest(self): global ctrl_x ctrl_x = 0 socket.send_string(("X:%d Y:%d" % (ctrl_x, ctrl_y))) def on_R3_y_at_rest(self): global ctrl_y ctrl_y = 0 socket.send_string(("X:%d Y:%d" % (ctrl_x, ctrl_y))) def main(): socket.bind("ipc:///penguinator/pubsub"); controller = ps4if(interface="/dev/input/js0", connecting_using_ds4drv=False) controller.debug = False controller.listen() while(True): time.sleep(1) main()