2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
2018-09-28 18:57:37 +00:00
|
|
|
if sys.version_info[0] >= 3:
|
2018-09-27 20:24:09 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-28 18:57:37 +00:00
|
|
|
else:
|
|
|
|
import PySimpleGUI27 as sg
|
2018-08-20 23:00:02 +00:00
|
|
|
|
|
|
|
# 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-09-24 22:01:00 +00:00
|
|
|
layout = [[sg.Text("Press a key or scroll mouse")],
|
|
|
|
[sg.Text("", size=(18,1), key='text')],
|
|
|
|
[sg.Button("OK", key='OK')]]
|
2018-08-20 23:00:02 +00:00
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
window = sg.Window("Keyboard Test", return_keyboard_events=True, use_default_focus=False).Layout(layout)
|
|
|
|
|
|
|
|
# ---===--- Loop taking in user input --- #
|
|
|
|
while True:
|
2018-10-15 20:07:23 +00:00
|
|
|
event, values = window.Read()
|
2018-09-24 22:01:00 +00:00
|
|
|
text_elem = window.FindElement('text')
|
2018-10-15 20:07:23 +00:00
|
|
|
if event in ("OK", None):
|
|
|
|
print(event, "exiting")
|
2018-09-24 22:01:00 +00:00
|
|
|
break
|
2018-10-15 20:07:23 +00:00
|
|
|
if len(event) == 1:
|
|
|
|
text_elem.Update(value='%s - %s' % (event, ord(event)))
|
|
|
|
if event is not None:
|
|
|
|
text_elem.Update(event)
|
2018-08-20 23:00:02 +00:00
|
|
|
|
|
|
|
|