PySimpleGUI/DemoPrograms/Demo_Keyboard_Realtime.py

26 lines
638 B
Python
Raw Normal View History

2018-09-27 20:24:09 +00:00
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
2018-09-27 20:24:09 +00:00
import PySimpleGUI as sg
else:
import PySimpleGUI27 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", return_keyboard_events=True, use_default_focus=False).Layout(layout)
2018-08-21 23:10:26 +00:00
while True:
2018-10-29 00:01:03 +00:00
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