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:
|
|
|
|
button, value = window.ReadNonBlocking()
|
2018-08-20 23:00:02 +00:00
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
if button == "OK":
|
|
|
|
print(button, value, "exiting")
|
|
|
|
break
|
|
|
|
if button is not None:
|
|
|
|
if len(button) == 1:
|
|
|
|
print('%s - %s'%(button, ord(button)))
|
|
|
|
else:
|
|
|
|
print(button)
|
|
|
|
elif value is None:
|
|
|
|
break
|