Передача события во внешний источникPython

Программы на Python
Anonymous
Передача события во внешний источник

Сообщение Anonymous »

Я работаю над библиотекой для контроллера PS5 DualSense, основанной на DualSense_controller.
Я хочу импортировать ее в свою программу на Python и каким-то образом передавать события из этой библиотеки.

Код: Выделить всё

from time import sleep
from dualsense_controller import DualSenseController

class DS5:
def __init__(self, controller_nb=0, debug = False):
'''
'''
# list availabe devices and throw exception when tzhere is no device detected
device_infos = DualSenseController.enumerate_devices()
if len(device_infos) < 1:
raise Exception('No DualSense Controller available.')

# flag, which keeps program alive
self.is_running = True
self.debug = debug

self.controller = DualSenseController(device_index_or_device_info=device_infos[controller_nb])
self.register_callbacks()
# enable/connect the device
self.controller.activate()

def register_callbacks(self):
# register the button callbacks
self.controller.btn_cross.on_down(self.on_cross_btn_pressed)
self.controller.btn_cross.on_up(self.on_cross_btn_released)

# register the error callback
self.controller.on_error(self.on_error)

# callback, when cross button is pressed, which enables rumble
def on_cross_btn_pressed(self):
if self.debug == True:
print('cross button pressed')

# callback, when cross button is released, which disables rumble
def on_cross_btn_released(self):
if self.debug == True:
print('cross button released')

def __exit__(self):
self.controller.deactivate()

if __name__ == "__main__":
Ds5 = DS5(debug=True)
while Ds5.is_running:
sleep(0.001)
Итак, когда, например, кнопка нажата, в этой программе будет выполнен какой-то метод.
Есть идеи?
Заранее спасибо.

Подробнее здесь: https://stackoverflow.com/questions/789 ... all-source

Вернуться в «Python»