Let's parse and process Key-Language! Given the input of a sequence of keyboard keypresses and/or special keys, write a program, function, etc. that outputs the product when all the actions are processed based on the following keyboard:
+-------------------------------------------------------+
| ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | - | + | |
| ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | _ | = |Del|
+-------------------------------------------------------+
|TAB| q | w | e | r | t | y | u | i | o | p | [ | ] | \ |
| | Q | W | E | R | T | Y | U | I | O | P | { | } | | |
+-------------------------------------------------------+
|CAPS | a | s | d | f | g | h | j | k | l | ; | ' | RET |
| | A | S | D | F | G | H | J | K | L | : | " | |
+-------------------------------------------------------+
| SHIFT | z | x | c | v | b | n | m | , | . | / | SHIFT |
| | Z | X | C | V | B | N | M | < | > | ? | |
+-------------------------------------------------------+
| |
| SPACEBAR |
+-------------------------------------------------------+
The keys that output actual characters not consisting of whitespace and are able to be modified by other keys will be known as "character keys", and those that modify the output of other keys or output whitespace will be known as "special keys". The alphabet character keys, which will be shown in the input with uppercase letters, can be modified with either Shift
or Caps Lock
to produce uppercase letters, and the rest of the character keys can only be modified with Shift
to produce their alternate characters. Therefore A
in the input corresponds to the a A
character key, whose normal output is a
and whose modified output, obtainable with either the Shift
or Caps Lock
key, is A
. On the other hand, /
, which corresponds to the / ?
character key, has a normal output of /
and a modified output of ?
obtainable with only with Shift
this time.
Rules
The input will always be a string consisting of a sequence of the character keys and special keys. The full special key to string mapping for the input (i.e. the format they are guaranteed to be in the input) and their corresponding actions/outputs are as follows:
<DEL> -> Delete the previous character (including whitespace). If called when string is empty, nothing happens. If called 2 or more times in a row, 2 consecutive deletes happen. For instance, "RE<DEL><DEL>" should return an empty string ("") and also "R<RET><DEL><DEL>E" should return just "E".
<CAPS> -> Enable Caps Lock until <CAPS> appears again, upon which it is disabled, although it is not guaranteed to be disabled by the end of the input. Enabling this only modifies the upcoming alphabet keys resulting in them outputting only uppercase letters. For instance, "<CAPS>RE<CAPS>" results in the output "RE", but <CAPS>.<CAPS> would still result in a ".".
<RET> -> Add a new line.
<SPC> -> Add a single blank space.
<TAB> -> Add 4 spaces.
<SHFT> -> Shift is held down resulting in the alternate character of the upcoming keypress to be output, after which the key is released. For instance, "<SHFT>A" results in the output "A", "<SHFT>1" results in the output "!", and "<SHFT>1234" results in the output "!234" as only the first upcoming keypress is modified and nothing else. It is guaranteed that a character key will succeed a <SHFT>. Therefore, <SHFT><SPC> is not a possible input.
An empty string is also possible as input, for which the output should be nothing.
- The use of any built-in that solves this problem directly is disallowed.
- The use of standard loopholes is disallowed.
Test Cases
Presented in the format Actual String Input -> Actual String Output
followed by an explanation for a few.
1<SHFT>2<TAB><CAPS>R.KAP.<SPC><SHFT>123 -> 1@ R.KAP. !23
Output
1
as the1
key is pressed without a toggle, then Shift is held down and the2
key is pressed resulting in the@
output. Then the Shift key is released and Tab is pressed, resulting in a 4 spaced indentation. Following up, the Caps Lock key is pressed, after which theR
,.
,K
,A
,P
, and.
keys are pressed, resulting in the outputR.KAP.
. Finally, a single space is output followed by shift resulting in!23
being output when the1
,2
, and3
keys are pressed at the end.<SHFT>ABCDEFG<SHFT>HIJK<SHFT>1<SHFT>2<SHFT>3<SHFT>4567890 -> AbcdefgHijk!@#$567890
The Shift key is held down followed by the
A
key, resulting in the outputA
followed by the outputbcdefg
when theB-G
keys are pressed. Then, the Shift key is held down again succeeded by theH
key, after which the output isH
, followed byijk
when theI-K
keys are pressed. Finally, the1-4
keys are all modified as shift is held down before each keypress resulting in the output!@#$
finished off by567890
when the5-0
keys re pressed.<CAPS>THIS<SPC>IS<SPC>IN<SPC>ALL<SPC>CAPS<CAPS><SPC>NOW<SPC>THIS<SPC>IS<SPC>IN<SPC>ALL<SPC>LOWERCASE -> THIS IS IN ALL CAPS now this is in all lowercase
<TAB><SPC><TAB><SHFT>1 -> !
<CAPS>WWW<CAPS>.CODEGOLF.STACKEXCHANGE<SHFT>.COM -> WWW.codegolf.stackexchange>com
PROGRAMMING<CAPS><SPC>IS<SPC><CAPS>AWESOME -> programming IS awesome
<DEL><RET><DEL><RET><DEL> -> "" (Empty String)
The delete key is pressed in the beginning after which nothing happens. Then, the Return key is pressed resulting in a new line, which is deleted after the backspace key is pressed again. Finally, the same sequence (new line followed by backspace) is repeated. After all this, the output is an empty string.
<SHFT>HI<SPC>HOW<SPC>ARE<SPC>YOU<SHFT>/<RET><SHFT>I<SPC><SHFT>AM<SPC>O<DEL><SHFT>GOOD<SHFT>1 -> Hi how are you?\nI Am Good!
<SHFT>,<CAPS>RET<CAPS><SHFT>. -> <RET>
The string
<RET>
should be the actual string output. Thus, this should not output a new line.<CAPS>67890,.;'[]<CAPS> -> 67890,.;'[]
<CAPS><SHFT>A -> A
RE<DEL><DEL> -> "" (Empty String)
U<RET><DEL><DEL>I -> i
<DEL><DEL><DEL>5<DEL> -> "" (Empty string)
"" (Empty String) -> "" (Empty String)
This is codegolf so the shortest code in bytes wins!
AbcdefgHijk!@#$567890
? Also, in test #8,<SHFT>
is at the end of the string, but the rules state: "It is guaranteed that a character key will succeed a <SHFT>." \$\endgroup\$