-
Notifications
You must be signed in to change notification settings - Fork 0
/
Keyboard.rb
373 lines (278 loc) · 5.27 KB
/
Keyboard.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
when I receive "initKeyboard"
set _string to ""
set _index to 0
set Inkey to ""
set _shift to FALSE
set _key to ""
set _semaphore to FALSE
show
when this sprite clicked
_ask
when up arrow key pressed
set _shift to TRUE
define _receive_key [char]
_set_key (char)
if _shift = TRUE or key up arrow pressed? then
broadcast (join "sh" (Inkey)) and wait
end
set _shift to FALSE
insert Inkey at 1 of _key_buf
if _semaphore = FALSE then
set _semaphore to TRUE
broadcast "keys"
end
when I receive "keys"
repeat until length of _key_buf = 0
set _key to item last of _key_buf
delete last of _key_buf
play sound "pop"
if Running = FALSE then
if _key = "♪" then
_cr
else
if _key = "◘" then
if length of TermInpBuf > 0 then
_backspace_scr
_backspace_scr
_backspace_buf
_print_one "_"
end
else
_print_n_buffer (_key)
end
end
end
end
set _semaphore to FALSE
define-atomic _set_key [char]
set Inkey to char
define _cr
set _semaphore to FALSE
_evaluate_print
define _ask
hide
ask "Enter FORTH:" and wait
set _semaphore to FALSE
set _index to 1
repeat length of TermInpBuf
_backspace_scr
end
repeat length of answer
set _string to letter _index of answer
if _string = "“" or _string = "”" then
set _string to "\""
end
_append_buf (_string)
change _index by 1
end
_backspace_scr
_print (join (TermInpBuf) " _")
_evaluate_print
show
define _evaluate_print
_backspace_scr
_print_one " "
broadcast "evaluate_buffer" and wait
broadcast "print_response" and wait
add TermInpBuf to History
set TermInpBuf to ""
_print_one "_"
define _print_n_buffer [char]
_backspace_scr
_append_buf (char)
_print (join (char) "_")
define-atomic _append_buf [char]
set TermInpBuf to (join (TermInpBuf) (char))
define _backspace_scr
if Current_column = 0 then
change Current_row by -1
if Current_row < 0 then
set Current_row to 0
else
broadcast (join "bs" (Current_row)) and wait
end
else
broadcast (join "bs" (Current_row)) and wait
end
define _backspace_buf
_head (TermInpBuf)
set TermInpBuf to _string
define _print [s]
set String to s
broadcast "print" and wait
define _print_one [char]
set Character to letter 1 of char
broadcast "print_one" and wait
define-atomic _head [s]
set _string to ""
set _index to 1
repeat length of s - 1
set _string to (join (_string) (letter _index of s))
change _index by 1
end
when I receive "sh1"
_set_key "!"
when I receive "sh2"
_set_key "@"
when I receive "sh3"
_set_key "#"
when I receive "sh4"
_set_key "["
when I receive "sh5"
_set_key "%"
when I receive "sh6"
_set_key "]"
when I receive "sh7"
_set_key "&"
when I receive "sh8"
_set_key "_"
when I receive "sh9"
_set_key "©"
when I receive "sh0"
_set_key "◘"
when I receive "shQ"
_set_key "'"
when I receive "shW"
_set_key "|"
when I receive "shE"
_set_key "~"
when I receive "shR"
_set_key "{"
when I receive "shT"
_set_key "\\"
when I receive "shY"
_set_key "}"
when I receive "shU"
_set_key "$"
when I receive "shI"
_set_key "("
when I receive "shO"
_set_key ")"
when I receive "shP"
_set_key "\""
when I receive "shA"
_set_key ""
set _shift to FALSE
if Running = FALSE then
_ask
end
when I receive "shS"
_set_key "`"
when I receive "shD"
_set_key "´"
when I receive "shF"
_set_key "¨"
when I receive "shG"
_set_key "€"
when I receive "shH"
_set_key "^"
when I receive "shJ"
_set_key "-"
when I receive "shK"
_set_key "+"
when I receive "shL"
_set_key "="
when I receive "shZ"
_set_key ":"
when I receive "shX"
_set_key ";"
when I receive "shC"
_set_key "?"
when I receive "shV"
_set_key "/"
when I receive "shB"
_set_key "*"
when I receive "shN"
_set_key "<"
when I receive "shM"
_set_key ">"
when I receive "sh."
_set_key ","
when I receive "sh◘"
_set_key "µ"
when I receive "sh♪"
_set_key "Å"
when I receive "sh "
_set_key ""
set _shift to FALSE
broadcast "break" and wait
when space key pressed
_receive_key " "
when a key pressed
_receive_key "A"
when b key pressed
_receive_key "B"
when c key pressed
_receive_key "C"
when d key pressed
_receive_key "D"
when e key pressed
_receive_key "E"
when f key pressed
_receive_key "F"
when g key pressed
_receive_key "G"
when h key pressed
_receive_key "H"
when i key pressed
_receive_key "I"
when j key pressed
_receive_key "J"
when k key pressed
_receive_key "K"
when l key pressed
_receive_key "L"
when m key pressed
_receive_key "M"
when n key pressed
_receive_key "N"
when o key pressed
_receive_key "O"
when p key pressed
_receive_key "P"
when q key pressed
_receive_key "Q"
when r key pressed
_receive_key "R"
when s key pressed
_receive_key "S"
when t key pressed
_receive_key "T"
when u key pressed
_receive_key "U"
when v key pressed
_receive_key "V"
when w key pressed
_receive_key "W"
when x key pressed
_receive_key "X"
when y key pressed
_receive_key "Y"
when z key pressed
_receive_key "Z"
when 0 key pressed
_receive_key "0"
when 1 key pressed
_receive_key "1"
when 2 key pressed
_receive_key "2"
when 3 key pressed
_receive_key "3"
when 4 key pressed
_receive_key "4"
when 5 key pressed
_receive_key "5"
when 6 key pressed
_receive_key "6"
when 7 key pressed
_receive_key "7"
when 8 key pressed
_receive_key "8"
when 9 key pressed
_receive_key "9"
when right arrow key pressed
_receive_key "."
when left arrow key pressed
_receive_key "◘"
when down arrow key pressed
_receive_key "♪"