@@ -237,8 +237,8 @@ async function menu(options, showOptions = true) {
237
237
}
238
238
239
239
while ( true ) {
240
- const evt = await readKey ( "??" , true ) ;
241
- const numKey = evt . keyCode - 48 ;
240
+ const key = await readKey ( "??" , true ) ;
241
+ const numKey = parseInt ( key ) ;
242
242
if ( numKey !== NaN && numKey >= 0 && numKey < options . length ) {
243
243
return options [ numKey ] . choice ;
244
244
}
@@ -253,22 +253,22 @@ async function waitKey() {
253
253
const interval = setInterval ( ( ) => {
254
254
const key = game . lastKey ;
255
255
if ( key ) {
256
- if ( key . key !== "Unidentified" // Chrome and alike on Android (not working)
257
- && key . key !== "Shift" && key . key !== "Control" && key . key !== "Alt" && key . key !== "Meta" ) {
258
- clearInterval ( interval ) ;
259
- console . log ( { key : game . lastKey } ) ;
260
- resolve ( game . lastKey ) ;
261
- }
256
+ clearInterval ( interval ) ;
257
+ console . log ( { key : game . lastKey } ) ;
258
+ resolve ( game . lastKey ) ;
262
259
}
263
260
} , 100 )
264
261
} ) ;
265
262
}
266
263
267
- function getKeyString ( evt ) {
268
- if ( evt ) {
269
- if ( evt . keyCode >= 48 && evt . keyCode <= 48 + 9 ) {
270
- return ( evt . keyCode - 48 ) . toString ( ) ;
271
- }
264
+ function getKeyString ( key ) {
265
+ if ( key ) {
266
+ if ( key === "\r" ) {
267
+ return "Enter" ;
268
+ }
269
+ else if ( / ^ [ 0 - 9 ] $ / . test ( key ) ) {
270
+ return key ;
271
+ }
272
272
}
273
273
return "Anykey" ;
274
274
}
@@ -283,18 +283,18 @@ async function readKey(prompt = "..", echo = false) {
283
283
resetStyle ( ) ;
284
284
285
285
// TODO: Add option to don't await input indefinitely - e.g. set timer and "run" CLS command from time to time.
286
- const evt = await waitKey ( ) ;
286
+ const key = await waitKey ( ) ;
287
287
288
288
if ( echo ) {
289
289
setStyle ( styles . bold + styles . white ) ;
290
- await typeln ( "\b" . repeat ( prompt . length ) + "<< " + getKeyString ( evt ) ) ;
290
+ await typeln ( "\b" . repeat ( prompt . length ) + "<< " + getKeyString ( key ) ) ;
291
291
resetStyle ( ) ;
292
292
}
293
293
else {
294
294
await type ( "\b" . repeat ( prompt . length ) ) ;
295
295
}
296
296
297
- return evt ;
297
+ return key ;
298
298
}
299
299
}
300
300
@@ -821,17 +821,9 @@ export class App {
821
821
t . open ( document . getElementById ( 'terminal' ) ) ;
822
822
fitAddon . fit ( ) ;
823
823
824
- t . onKey ( e => {
825
- window . game . lastKey = e . domEvent ;
826
- } ) ;
827
-
828
- /*
829
- t.attachCustomKeyEventHandler(evt => {
830
- if (evt.type === "keyup") {
831
- window.game.lastKey = evt;
832
- }
824
+ t . onData ( e => {
825
+ window . game . lastKey = e ;
833
826
} ) ;
834
- */
835
827
836
828
window . addEventListener ( "resize" , evt => {
837
829
fitAddon . fit ( ) ;
0 commit comments