回答編集履歴

1

追記

2020/04/06 01:50

投稿

otn
otn

スコア85528

test CHANGED
@@ -15,3 +15,59 @@
15
15
 
16
16
 
17
17
  あと、同じ処理を並べるのなく、1つの関数で出来るようにしましょう。
18
+
19
+ ###追記:元のプログラムの単純改善
20
+
21
+ ```Python
22
+
23
+ import msvcrt
24
+
25
+ import time
26
+
27
+ import os
28
+
29
+
30
+
31
+ import winsound as ws
32
+
33
+
34
+
35
+ def blind_touch():
36
+
37
+ while True:
38
+
39
+ time.sleep(0.01)
40
+
41
+ if msvcrt.kbhit():
42
+
43
+ kb = msvcrt.getch().decode()
44
+
45
+ print(kb)
46
+
47
+ if kb == "\r":
48
+
49
+ break
50
+
51
+ elif kb.isalpha():
52
+
53
+ sound_name = f'alphabet01_{kb}_01.wav'
54
+
55
+ elif kb.isdigit():
56
+
57
+ sound_name = f'num00{kb}_01.wav'
58
+
59
+ else:
60
+
61
+ continue
62
+
63
+ if os.path.exists(sound_name):
64
+
65
+ ws.PlaySound(sound_name,ws.SND_FILENAME)
66
+
67
+
68
+
69
+ if __name__ == "__main__":
70
+
71
+ blind_touch()
72
+
73
+ ```