do something when "events" are empty (no user input)
Is not an Issue but how can I do something when there was a interval without any user input?
for event in events: do some stuff if not events: #like if events are empty because there was no user input do some other stuff
I have the same issue (and I would call it an issue ;) To talk about it in a more programmatic way: there's no non-blocking way to read input.
If you guys are using Linux, I made a fork that handles this issue for gamepads by making the read() call non-blocking. Unfortunately, I don't think it will work on other operating systems (and I haven't tested it with the keyboard or mouse), but the changes I made might be enough to get you started.
https://github.com/trevorablett/inputs/tree/non-blocking-gamepad
I'm not sure this is the same problem, but it could be related:
while 1:
events = get_key()
for event in events:
print(event.ev_type, event.code, event.state)
freezes on Windows. If events could be a list, this should work. To solve the problem here, you can do what the keyboard example does:
while 1:
events = get_key()
if events:
for event in events:
print(event.ev_type, event.code, event.state)
else:
do some other stuff
I edited the inputs.py file from the library so it would stream data continuously about the position of the buttons and joysticks on a controller. I only edited the controller section because thats the only part that im using, but the code could be applied to any of the input devices. Basically, I just made it so that an event registers all the time instead of only when something is changed, by commenting out the if oldEvent = newEvent: type lines, and put a deltaTime delay in the sending of the position because if you send all the events without this there is way to many to handle and the program you are reading into will get backed up.
just change it to a .py and it will work like this for gamepads
If you guys are using Linux, I made a fork that handles this issue for gamepads by making the read() call non-blocking. Unfortunately, I don't think it will work on other operating systems (and I haven't tested it with the keyboard or mouse), but the changes I made might be enough to get you started.
https://github.com/trevorablett/inputs/tree/non-blocking-gamepad
Thanks a lot @trevorablett , it works like a charm!