1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#!/bin/python
import evdev
iDevices = {}
iDeviceNo = 0
def updateInputDevices(force = False, init = False):
global iDeviceNo
if init:
iDevices = {}
iDeviceNo = 0
deviceFileList = evdev.list_devices()
if not force:
if len(deviceFileList) == iDeviceNo:
return
iDeviceNo = len(deviceFileList)
mode = 'ALL'
iDevicesFiles = []
for device in iDevices:
iDevicesFiles.append(iDevices[device].fn)
print(len(iDevicesFiles),len(deviceFileList))
if len(iDevicesFiles) == len(deviceFileList):
return
for deviceFile in deviceFileList:
try:
if deviceFile in iDevicesFiles:
print('skip')
continue
open(deviceFile)
# 3 pos absolute
# 2 pos relative
# 1 Keys
currDevice = evdev.InputDevice(deviceFile)
cap = currDevice.capabilities()
if mode in ['ALL','NOMICE']:
if 1 in cap:
if 116 in cap[1] and len(cap[1]) < 5:
print('power')
continue
if mode == 'ALL':
iDevices[currDevice.fd] = currDevice
print('Device added:' + iDevices[currDevice.fd].name)
elif mode == 'NOMICE':
if not ((2 in cap) or (3 in cap)):
iDevices[currDevice.fd] = currDevice
print('Device added:' + iDevices[currDevice.fd].name)
elif currDevice.name.upper() in mode.split(','):
iDevices[currDevice.fd] = currDevice
print('Device added:' + iDevices[currDevice.fd].name)
except Exception as e:
print("Skip Inputdevice : " + deviceFile +' ' + str(e))
updateInputDevices()
|