2018-08-20 23:00:02 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
|
2018-08-21 23:10:26 +00:00
|
|
|
with sg.FlexForm("Realtime Keyboard Test", return_keyboard_events=True, use_default_focus=False) as form:
|
|
|
|
layout = [[sg.Text("Hold down a key")],
|
|
|
|
[sg.SimpleButton("OK")]]
|
2018-08-20 23:00:02 +00:00
|
|
|
|
|
|
|
form.Layout(layout)
|
2018-08-21 23:10:26 +00:00
|
|
|
|
2018-08-20 23:00:02 +00:00
|
|
|
while True:
|
|
|
|
button, value = form.ReadNonBlocking()
|
|
|
|
|
2018-08-21 23:10:26 +00:00
|
|
|
if button == "OK":
|
|
|
|
print(button, value, "exiting")
|
2018-08-20 23:00:02 +00:00
|
|
|
break
|
|
|
|
if button is not None:
|
2018-09-04 23:43:22 +00:00
|
|
|
if len(button) == 1:
|
|
|
|
print('%s - %s'%(button, ord(button)))
|
|
|
|
else:
|
|
|
|
print(button)
|
2018-08-20 23:00:02 +00:00
|
|
|
elif value is None:
|
|
|
|
break
|