linux/reicast-joyconfig: Discard ALL events in the clear_events() function

This should fix #962.
This commit is contained in:
Jan Holthuis 2016-09-12 13:59:38 +02:00
parent 04137ca950
commit dc025c7502
1 changed files with 12 additions and 3 deletions

View File

@ -6,6 +6,7 @@ from __future__ import print_function
import sys import sys
import re import re
import os import os
import select
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
import ConfigParser as configparser import ConfigParser as configparser
INPUT_FUNC = raw_input INPUT_FUNC = raw_input
@ -42,9 +43,17 @@ def list_devices():
def clear_events(dev): def clear_events(dev):
try: try:
event = dev.read_one() # This is kinda hacky, but fixes issue #962:
while(event is not None): # https://github.com/reicast/reicast-emulator/issues/962
event = dev.read_one() # First, we read all available input events, then we wait for up to a
# quarter second, then we attempt to read event more input events. This
# should make sure that all available input events have been read (and
# discarded).
for event in iter(dev.read_one, None):
pass
select.select([dev], [], [], 0.50)
for event in iter(dev.read_one, None):
pass
except (OSError, IOError): except (OSError, IOError):
# BlockingIOErrors should only occur if someone uses the evdev # BlockingIOErrors should only occur if someone uses the evdev
# module < v0.4.4. BlockingIOError inherits from OSError, so we # module < v0.4.4. BlockingIOError inherits from OSError, so we