You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: MiniScript-cpp/README-key.md
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,28 +8,32 @@
8
8
|`key.get`| compatible |
9
9
|`key.put(keyChar)`| compatible |
10
10
|`key.clear`| compatible |
11
-
|`key.pressed(keyName="space")`| not ported |
12
-
|`key.keyNames`| not ported |
13
-
|`key.axis(axis="Horizontal")`| not ported |
14
-
|`key._putInFront(keyChar)`| (non-standard) same as `key.put` but instead of adding its arg at the end of the input buffer, inserts it at the beginning|
15
-
|`key._echo`| (non-standard, only unixes) property that controls whether typed characters are echoed in the terminal |
16
-
|`key._scanMap`| (non-standard) property that controls how scan codes and escape sequences are mapped to the values that `key.get` is expected to return |
11
+
|`key.pressed(keyName="space")`|(not ported)|
12
+
|`key.keyNames`|(not ported)|
13
+
|`key.axis(axis="Horizontal")`|(not ported)|
14
+
|`key._putInFront(keyChar)`| (non-standard) same as `key.put` but inserts its arg at the beginning of the input buffer |
15
+
|`key._echo`| (non-standard, only unixes) boolean property that controls whether typed characters are echoed in the terminal |
16
+
|`key._scanMap`| (non-standard) property that controls how scan codes and escape sequences are mapped to the values that `key.get` is expected to return (`map` type) |
17
17
18
-
There's a small demo that demonstrates the use of `key.available`and `key.get`: `demo/tetris.ms`.
18
+
There's a small script that demonstrates the use of `key.available`, `key.get`and `key._echo`: `demo/tetris.ms`.
19
19
20
20
21
21
## Implementation of the input buffer
22
22
23
-
The functions of this module maintain their shared internal buffer where key presses are stored.
23
+
Functions of this module maintain a shared internal buffer where key presses are stored.
24
24
25
25
It's implemented as a `SimpleVector` of entries where each entry is structure of two fields:
26
26
27
+
| Field | Description |
28
+
|---|---|
27
29
|`c`| character code point of a regular (symbol) key |
28
30
|`scanCode`| a code of a special key |
29
31
30
32
Only one of these fields is non-zero at any times.
31
33
32
-
This data type allows registering key presses on unixes where only code points are used, and Windows where key presses generate either a code point or a sequence of two integers: `0` and a scan code.
34
+
This data type was chosen to register key presses on various systems:
35
+
- On unixes only code points are used
36
+
- On Windows key presses may generate either a code point or a sequence of two integers: `0` and a scan code.
33
37
34
38
35
39
## Scan map
@@ -38,9 +42,9 @@ Terminals vary in how they report special keys' presses.
38
42
39
43
For example this is what \[Arrow up\] becomes in the Linux terminal: `char(27) + "[A"` (3 ASCII characters). The same key press on Windows produces `0` followed by scan code `72`. Finally, on Mini Micro it's `char(19)`.
40
44
41
-
*Scan maps* is an internal mechanism of the `key` module that converts all various values into the same values that are returned by Mini Micro's `key.get` and hence should ensure portability of scripts.
45
+
*Scan maps* is a mechanism of the `key` module that converts all various values into the same values that are returned by Mini Micro's `key.get` and hence facilitates portability of scripts.
42
46
43
-
Scan maps are stored in a `key._scanMap` property and are MiniScript maps where the keys are either `number` type (in case you're mapping a scan code) or `string` type (in case of a sequence of characters), and the values are what you want to be returned by `key.get`.
47
+
Scan maps are MiniScript `map`s (stored as a `key._scanMap` property) where the keys are either `number` type (in case you're mapping a scan code) or `string` type (in case of a sequence of characters), and the values are what you want to be returned by `key.get`.
44
48
45
49
So, to overcome the above \[Arrow up\] problem one could define `key._scanMap` as
46
50
@@ -56,8 +60,8 @@ There is already a predefined scan map in the `key` module that covers certain s
56
60
57
61
## Scan map optimization
58
62
59
-
In games, handling the user input is tipically a part of a game loop.
63
+
In games, handling the user input is tipically a part of a game loop and thus needs to be fast.
60
64
61
-
So, to make `key.get` a bit faster and avoid converting strings into code points on each frame, the scan map gets populated with optimized keys.
65
+
To avoid converting strings into code points on each frame inside `key.get`, the scan map gets populated with optimized keys.
62
66
63
67
This optimization happens on assignment to the `_scanMap` property via the `*AssignOverride` trick.
0 commit comments