Python Forum
Read a single event (keypress) from asyncio
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read a single event (keypress) from asyncio
#4
Remove all the waits while continuing to print the events. If the code shows the event toggling between 04 and 00 it means that there are multiple events sent and you are not looking at the same event over and over.

Unless my understanding of evdev.InputDevice is wrong, putting a delay in your event processor (rec_code()) will not change the number of button press events. The events will remain in the event queue until read. The only thing the wait does is make your code take a longer time to process all the events. It sounds like you came to the same conclusion.

With your code set up to print all events, press and hold a button. Do you get a stream of 4, 0, events or just one? If you get many events my guess is the remote does the same thing as key-repeat on a keyboard; it is generating press/release events as long as hold the button down. Is the delay the same between each 04 event? To make this easier to spot I would print the elapsed time since last event. Something like this:
async def rec_code():
    end_time = time()
    async for event in irr.async_read_loop():
        start_time, end_time =endtime,  time()
        print (end_time - start_time, event)
Once you know the delay between these repeat events you can use elapsed time to filter them out.
async def rec_code():
    end_time = time()
    async for event in irr.async_read_loop():
        start_time, end_time =endtime,  time()
        if end_time - start_time > repeat_time:
            # Process button press
Reply


Messages In This Thread
RE: Read a single event (keypress) from asyncio - by deanhystad - May-26-2021, 07:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [GPX] Read all trkpt, and merge into single track? Winfried 0 1,550 Jan-30-2020, 04:08 PM
Last Post: Winfried
  Asyncio StreamReader read method doesn't respect timeout when using SSL dukadahake 0 3,499 Jul-24-2019, 11:55 AM
Last Post: dukadahake
  Keypress when running a python app in a console on windows Stephen 6 9,026 Apr-16-2019, 12:38 PM
Last Post: Stephen
  Using asyncio to read text file and load GUI QueenSvetlana 1 4,816 Nov-09-2017, 02:55 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020