2018-08-20 23:00:02 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
|
|
|
|
# Recipe for getting keys, one at a time as they are released
|
|
|
|
# If want to use the space bar, then be sure and disable the "default focus"
|
|
|
|
|
2018-08-21 23:10:26 +00:00
|
|
|
with sg.FlexForm("Keyboard Test", return_keyboard_events=True, use_default_focus=False) as form:
|
|
|
|
text_elem = sg.Text("", size=(18,1))
|
|
|
|
layout = [[sg.Text("Press a key or scroll mouse")],
|
2018-08-20 23:00:02 +00:00
|
|
|
[text_elem],
|
2018-08-21 23:10:26 +00:00
|
|
|
[sg.SimpleButton("OK")]]
|
2018-08-20 23:00:02 +00:00
|
|
|
|
|
|
|
form.Layout(layout)
|
|
|
|
# ---===--- Loop taking in user input --- #
|
|
|
|
while True:
|
2018-08-29 14:28:03 +00:00
|
|
|
button, value = form.Read()
|
2018-08-20 23:00:02 +00:00
|
|
|
|
2018-08-21 23:10:26 +00:00
|
|
|
if button == "OK" or (button is None and value is None):
|
|
|
|
print(button, "exiting")
|
2018-08-20 23:00:02 +00:00
|
|
|
break
|
2018-08-29 14:28:03 +00:00
|
|
|
if len(button) == 1:
|
2018-09-11 12:38:38 +00:00
|
|
|
text_elem.Update(value='%s - %s' % (button, ord(button)))
|
2018-08-20 23:00:02 +00:00
|
|
|
if button is not None:
|
|
|
|
text_elem.Update(button)
|
|
|
|
|
|
|
|
|