Exemplo n.º 1
0
def print_device_info(devicefd):
	version = c_int()

	if libc.ioctl(devicefd, EVIOCGVERSION, byref(version)):
		print("evtest: can't get version")
		sys.exit(os.EX_IOERR)

	version = version.value
	print('Input driver version is {}.{}.{}'.format(version >> 16,
		(version >> 8) & 0xff, version & 0xff))

	id = input_id()
	libc.ioctl(devicefd, EVIOCGID, byref(id))
	print('Input device ID: bus {0:#x} vendor {1:#x} product {2:#x} version {3:#x}'.format(
		id.bustype, id.vendor, id.product, id.version))

	name = (c_char * 256)()
	libc.ioctl(devicefd, EVIOCGNAME(sizeof(name)), byref(name))
	print('Input device name: "{}"'.format(name.value.decode('utf-8')));

	evbits = (c_ulong * num_longs(EV_MAX))()
	libc.ioctl(devicefd, EVIOCGBIT(0, EV_MAX), byref(evbits))
	print('Supported events:')

	for type in range(EV_MAX):
		if test_bit(type, evbits) and type != Events.EV_REP:
			print('  Event type {} ({})'.format(type, Events.reverse_mapping(type)))
			if type == Events.EV_SYN:
				continue

			codebits = (c_ulong * num_longs(KEY_MAX))()
			libc.ioctl(devicefd, EVIOCGBIT(type, KEY_MAX), byref(codebits));
			for code in range(KEY_MAX):
				if test_bit(code, codebits):
					print('    Event code {} ({})'.format(code, codename(type, code)))

	if test_bit(Events.EV_REP, evbits):
		print('Key repeat handling:')
		print('  Repeat type {} ({})'.format(Events.EV_REP, Events.reverse_mapping(Events.EV_REP)))
		repbits = (c_uint * REP_CNT)()
		libc.ioctl(devicefd, EVIOCGREP, byref(repbits))
		for rep in range(REP_CNT):
			print('    Repeat code {} ({})'.format(rep, Repeats.reverse_mapping(rep)))
			print('      Value {}'.format(repbits[rep]))
Exemplo n.º 2
0
def print_single_event(event):
	code = event.code
	type = event.type
	print('Event: time {}.{}, '.format(event.tv_sec, event.tv_usec), end='')
	if type == Events.EV_SYN:
		if code == Syns.SYN_MT_REPORT:
			print('++++++++++++++ %s ++++++++++++' % codename(type, code))
		elif code == Syns.SYN_DROPPED:
			print('>>>>>>>>>>>>>> %s <<<<<<<<<<<<' % codename(type, code))
		else:
			print('-------------- %s ------------' % codename(type, code))
	else:
		eventstr = 'type {} ({}), code {} ({}), '.format(
			type, Events.reverse_mapping(type),
			code, codename(type, code) )
		print(eventstr, end='')
		if (type == Events.EV_MSC and (code == Misc.MSC_RAW or code == Misc.MSC_SCAN)):
			print('value {0:#x}'.format(event.value))
		else:
			print('value {}'.format(event.value))
Exemplo n.º 3
0
def codename(type, code):
	name = Events.reverse_mapping(type)
	return Names[name].reverse_mapping(code)