def _find_device(self):
        #:bug: the device node might not be immediately available
        time.sleep(0.1)

        for fn in util.list_devices('/dev/input/'):
            d = device.InputDevice(fn)
            if d.name == self.name:
                return d
Exemple #2
0
    def _find_device(self):
        #:bug: the device node might not be immediately available
        time.sleep(0.1)

        for fn in util.list_devices('/dev/input/'):
            d = device.InputDevice(fn)
            if d.name == self.name:
                return d
Exemple #3
0
 def _connect(self):
     if (not self._isConnected):
         for eventPath in util.list_devices(DEV_INPUT_PATH):
             if util.is_device(eventPath):
                 device = InputDevice(eventPath)
                 if device.name == CONTROLLER_NAME:
                     print("Controller found: " + device.name)
                     self.gamepad = device
                     self._isConnected = True
                 else:
                     print("Wrong controller: " + device.name)
                     device.close()
Exemple #4
0
 def from_name(self, device_name):
     info = Popen(["xinput", "list", "--short", device_name], stdout=PIPE).communicate()[0]
     try:
         device_name, self.xid = search(r"^([a-zA-Z0-9 _]+?)\s*id=(\d+)", info).groups(0)
         path_info = Popen(["xinput", "list-props", self.xid], stdout=PIPE).communicate()[0]
         self.path = search(r'Device Node \(\d*\):\s*"([a-zA-Z0-9_/]*)"', path_info).group(1)
     except AttributeError:
         path = [dev.fn for dev in map(InputDevice, list_devices()) if dev.name==device_name]
         if not path:
             raise DeviceError("No device with name %s" % device_name)
         if len(path) > 1:
             raise DeviceError("Multiple devices with name %s, use xid or path instead,"
                           "or prefix name with 'keyboard' or 'pointer':" % device_name)
def run():
	from evdev import InputDevice, categorize, ecodes, KeyEvent, util

	devices = [InputDevice(fn) for fn in util.list_devices()]

	found = False

	for device in devices:

		if device.name == 'Logitech Gamepad F710' or device.name == 'Logitech Gamepad F310':
			gamePad = InputDevice(device.fn)
			found = True
			break


	if found == False:
		print("Device not found")
		return

	print("\nPrint gamepad object information\n")
	print (gamePad)
	print("\n")


	print("Press gamepad buttons\n")


	for event in gamePad.read_loop():
		if event.type == ecodes.EV_KEY:
			keyevent = categorize(event)
			print(keyevent)
			print("")

			if keyevent.keystate == KeyEvent.key_down:
				print('key down detected')
				print("keyevent.keycode")
				print(keyevent.keycode)
				print("")

				if keyevent.keycode[1] == 'BTN_X':
					print('button X\n')
				elif keyevent.keycode[0] == 'BTN_B':
					print('button B\n')
				elif keyevent.keycode[0] == 'BTN_A':
					print('button A\n')
				elif keyevent.keycode[1] == 'BTN_Y':
					print('button Y\n')
				elif keyevent.keycode == 'BTN_TL':
					print('button thumb left\n')
				elif keyevent.keycode == 'BTN_TR':
					print("button thumb right\n")
def run():
    from evdev import InputDevice, categorize, ecodes, KeyEvent, util

    devices = [InputDevice(fn) for fn in util.list_devices()]

    found = False

    for device in devices:

        if device.name == 'Logitech Gamepad F710' or device.name == 'Logitech Gamepad F310':
            gamePad = InputDevice(device.fn)
            found = True
            break

    if found == False:
        print("Logitech Gamepad device not found")
        return

    print("\nPress thumbstick\n")

    for event in gamePad.read_loop():
        # event type 3 is EV_ABS
        if event.type == ecodes.EV_ABS:
            absaxisevent = categorize(event)
            print(absaxisevent)
            print("")

            if event.code == ecodes.ABS_X:  # ecodes.ABS_X is 3
                print('ABS_X detected, event.value: ', event.value)
            elif event.code == ecodes.ABS_Y:  # ecodes.ABS_Y is 1
                print('ABS_Y detected, event value: ', event.value)
            elif event.code == ecodes.ABS_RX:
                print('ABS_RX dectected, event.value: ', event.value)
            elif event.code == ecodes.ABS_RY:
                print('ABS_RY detected, event.value: ', event.value)
            elif event.code == ecodes.ABS_Z:
                print('ABS_Z detected, event.value: ', event.value)
            elif event.code == ecodes.ABS_RZ:
                print('ABS_RZ detected, event.value: ', event.value)
            elif event.code == ecodes.ABS_HAT0X:
                print('ABS_HAT0X detected, event.value: ', event.value)
            elif event.code == ecodes.ABS_HAT0Y:
                print('ABS_HAT0Y detected, event.value: ', event.value)
from evdev import InputDevice, categorize, ecodes, KeyEvent, util

devices = [InputDevice(fn) for fn in util.list_devices()]

for device in devices:

    if device.name == 'Logitech Gamepad F710' or device.name == 'Logitech Gamepad F310':
        gamePad = InputDevice(device)
        break

print("\nPrint gamepad object information\n")
print(gamePad)
print("\n")

print("Press gamepad buttons\n")

for event in gamePad.read_loop():
    if event.type == ecodes.EV_KEY:
        keyevent = categorize(event)
        print(keyevent)
        print("")

        if keyevent.keystate == KeyEvent.key_down:
            print('key down detected')
            print("keyevent.keycode")
            print(keyevent.keycode)
            print("")

            if keyevent.keycode[1] == 'BTN_X':
                print('button X\n')
            elif keyevent.keycode[0] == 'BTN_B':
Exemple #8
0
from evdev import ecodes, InputDevice, ff, util
import time

dev = None

# Find first EV_FF capable event device (that we have permissions to use).
for name in util.list_devices():
    dev = InputDevice(name)
    if ecodes.EV_FF in dev.capabilities():
        break

if dev is None:

    print("Sorry, no FF capable device found")

else:
    print("found " + dev.name + " at " + dev.path)
    print("Preparing FF effect...")

    rumble = ff.Rumble(strong_magnitude=0xc000, weak_magnitude=0xc000)
    effect_type = ff.EffectType(ff_rumble_effect=rumble)
    duration_ms = 1000

    effect = ff.Effect(
        ecodes.FF_RUMBLE,  # type
        -1,  # id (set by ioctl)
        0,  # direction
        ff.Trigger(0, 0),  # no triggers
        ff.Replay(duration_ms, 0),  # length and delay
        ff.EffectType(ff_rumble_effect=rumble))