diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-08-16 11:54:23 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-08-16 11:54:23 +0800 |
commit | 9542deeb483a00b6fabed7574720926ce97d7511 (patch) | |
tree | 0f2c1f72c03dd4693fd59df67544d2a4dddc5494 /projects/12/Keyboard.jack | |
parent | 9c0cb1d1c32724fc95ac9548e4f8d873d3adaccc (diff) |
Projects, 01-06 completed
Diffstat (limited to 'projects/12/Keyboard.jack')
-rw-r--r-- | projects/12/Keyboard.jack | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/projects/12/Keyboard.jack b/projects/12/Keyboard.jack new file mode 100644 index 0000000..03e1031 --- /dev/null +++ b/projects/12/Keyboard.jack @@ -0,0 +1,62 @@ +// This file is part of www.nand2tetris.org
+// and the book "The Elements of Computing Systems"
+// by Nisan and Schocken, MIT Press.
+// File name: projects/12/Keyboard.jack
+
+/**
+ * A library for handling user input from the keyboard.
+ */
+class Keyboard {
+
+ /** Initializes the keyboard. */
+ function void init() {
+ }
+
+ /**
+ * Returns the character of the currently pressed key on the keyboard;
+ * if no key is currently pressed, returns 0.
+ *
+ * Recognizes all ASCII characters, as well as the following keys:
+ * new line = 128 = String.newline()
+ * backspace = 129 = String.backspace()
+ * left arrow = 130
+ * up arrow = 131
+ * right arrow = 132
+ * down arrow = 133
+ * home = 134
+ * End = 135
+ * page up = 136
+ * page down = 137
+ * insert = 138
+ * delete = 139
+ * ESC = 140
+ * F1 - F12 = 141 - 152
+ */
+ function char keyPressed() {
+ }
+
+ /**
+ * Waits until a key is pressed on the keyboard and released,
+ * then echoes the key to the screen, and returns the character
+ * of the pressed key.
+ */
+ function char readChar() {
+ }
+
+ /**
+ * Displays the message on the screen, reads from the keyboard the entered
+ * text until a newline character is detected, echoes the text to the screen,
+ * and returns its value. Also handles user backspaces.
+ */
+ function String readLine(String message) {
+ }
+
+ /**
+ * Displays the message on the screen, reads from the keyboard the entered
+ * text until a newline character is detected, echoes the text to the screen,
+ * and returns its integer value (until the first non-digit character in the
+ * entered text is detected). Also handles user backspaces.
+ */
+ function int readInt(String message) {
+ }
+}
|