PySimpleGUI/DemoPrograms/Demo_Keyboard_Realtime.py

25 lines
585 B
Python
Raw Normal View History

2018-09-27 20:24:09 +00:00
#!/usr/bin/env python
import PySimpleGUI as sg
2018-08-20 23:00:02 +00:00
layout = [[sg.Text("Hold down a key")],
[sg.Button("OK")]]
2018-08-20 23:00:02 +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
while True:
event, values = window.read(timeout=0)
2018-08-20 23:00:02 +00:00
if event == "OK":
print(event, values, "exiting")
break
2018-10-29 00:01:03 +00:00
if event is not sg.TIMEOUT_KEY:
if len(event) == 1:
print('%s - %s' % (event, ord(event)))
else:
print(event)
2018-10-29 00:01:03 +00:00
elif event is None:
break
window.close()