@@ -0,0 +1,1751 @@
+#! /usr/bin/python3%0A%0Afrom time import time, localtime, gmtime, strftime%0Afrom math import modf%0Aimport queue%0Afrom gpiozero import Button%0A%0AGPIO_PIN = 23%0AGPIO_DEBOUNCE = 0.2%0AGPIO_HOLDTIME = 1%0ATS_FORMAT = '%25H:%25M:%25S'%0ADEVT_FORMAT = '%25S'%0APIN_EVENT_PRESSED = 1%0APIN_EVENT_RELEASED = 2%0APIN_EVENT_HELD = 3%0A%0Aevent_text = %7B%0A    PIN_EVENT_PRESSED: 'pressed',%0A    PIN_EVENT_RELEASED: 'released',%0A    PIN_EVENT_HELD: 'held'%0A%7D%0A%0Adef time_conv(t, format=TS_FORMAT, local=True):%0A    if t:%0A        ts = round(t, 3)%0A        if local:%0A            cf = localtime%0A        else:%0A            cf = gmtime%0A        ts_string = strftime(format, cf(ts))%0A        ts_fraction = int(modf(ts)%5B0%5D * 1000)%0A        return '%7B%7D.%7B:03d%7D'.format(ts_string, ts_fraction)%0A    else:%0A        return 'None'%0A%0Adef gpio_handler_pressed(device):%0A    global q%0A    q.put((device, PIN_EVENT_PRESSED, time()))%0A    return%0A%0Adef gpio_handler_released(device):%0A    global q%0A    q.put((device, PIN_EVENT_RELEASED, time()))%0A    return%0A%0Adef gpio_handler_held(device):%0A    global q%0A    q.put((device, PIN_EVENT_HELD, time()))%0A    return%0A%0Aq = queue.Queue()%0Abtn = Button(GPIO_PIN, pull_up=True, bounce_time=GPIO_DEBOUNCE, hold_time=GPIO_HOLDTIME, hold_repeat=True)%0Abtn.when_pressed = gpio_handler_pressed%0Abtn.when_released = gpio_handler_released%0Abtn.when_held = gpio_handler_held%0A%0Awhile True:%0A    (device, pin_event, t) = q.get()%0A    pin = device.pin.number%0A    print('%7B%7D: Pin %7B%7D %7B%7D: active=%7B%7D, pressed=%7B%7D, held=%7B%7D, active_time=%7B%7D, held_time=%7B%7D'.format(time_conv(t), pin,%0A        event_text%5Bpin_event%5D, device.is_active, device.is_pressed, device.is_held,%0A        time_conv(device.active_time, format=DEVT_FORMAT, local=False),%0A        time_conv(device.held_time, format=DEVT_FORMAT, local=False)))%0A    q.task_done()%0A%0A

Test script pintst-gpiozero.py added: - It uses 'gpiozero' library and its 'Button' object for detecting pin state changes. - Type of state change passed from event handler to main thread by means of 'Queue' object of 'queue' library.