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
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
layout = [[sg.Text("Hold down a key")],
|
|
|
|
[sg.Button("OK")]]
|
2018-08-20 23:00:02 +00:00
|
|
|
|
2018-09-24 22:01:00 +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
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
while True:
|
2018-10-15 20:07:23 +00:00
|
|
|
event, values = window.ReadNonBlocking()
|
2018-08-20 23:00:02 +00:00
|
|
|
|
2018-10-15 20:07:23 +00:00
|
|
|
if event == "OK":
|
|
|
|
print(event, values, "exiting")
|
2018-09-24 22:01:00 +00:00
|
|
|
break
|
2018-10-15 20:07:23 +00:00
|
|
|
if event is not None:
|
|
|
|
if len(event) == 1:
|
|
|
|
print('%s - %s' % (event, ord(event)))
|
2018-09-24 22:01:00 +00:00
|
|
|
else:
|
2018-10-15 20:07:23 +00:00
|
|
|
print(event)
|
|
|
|
elif values is None:
|
2018-09-24 22:01:00 +00:00
|
|
|
break
|