2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-08-20 23:00:02 +00:00
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
layout = [[sg.Text("Hold down a key")],
|
|
|
|
[sg.Button("OK")]]
|
2018-08-20 23:00:02 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window = sg.Window("Realtime Keyboard Test", layout, return_keyboard_events=True,
|
|
|
|
use_default_focus=False)
|
2018-08-21 23:10:26 +00:00
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read(timeout=0)
|
2018-08-20 23:00:02 +00:00
|
|
|
|
2018-10-15 20:07:23 +00:00
|
|
|
if event == "OK":
|
|
|
|
print(event, values, "exiting")
|
2018-09-24 22:01:00 +00:00
|
|
|
break
|
2018-10-29 00:01:03 +00:00
|
|
|
if event is not sg.TIMEOUT_KEY:
|
2018-10-15 20:07:23 +00:00
|
|
|
if len(event) == 1:
|
|
|
|
print('%s - %s' % (event, ord(event)))
|
2018-09-24 22:01:00 +00:00
|
|
|
else:
|
2018-10-15 20:07:23 +00:00
|
|
|
print(event)
|
2020-05-07 10:22:59 +00:00
|
|
|
elif event == sg.WIN_CLOSED:
|
2018-09-24 22:01:00 +00:00
|
|
|
break
|
2019-10-23 20:10:03 +00:00
|
|
|
|
|
|
|
window.close()
|