Emulate the Professor's typing

8

1

Emulate the Professor's typing

Background

Unfortunately, the Professor is not able to use his keyboard properly: whenever he is meant to use the Shift key, he presses Caps Lock once before typing, and doesn't bother to correct himself. If there are two or more keys in a row that require Shift, he presses Caps Lock before the first one and does nothing before the others.

As his secretary, I want to replicate this effect so that people think that he is the one replying to his emails, not me. He knows his typing looks stupid, but he doesn't care.

Task

Write a program that takes STDIN or file input of some text, and then outputs that text as if it had been typed by the Professor.

This is code golf, and standard loopholes are not allowed.

Keyboard layout

Default:
` 1 2 3 4 5 6 7 8 9 0 - =
   q w e r t y u i o p [ ]
    a s d f g h j k l ; ' #
   \ z x c v b n m , . /

With shift:
¬ ! " £ $ % ^ & * ( ) _ +
   Q W E R T Y U I O P { }
    A S D F G H J K L : @ ~
   | Z X C V B N M < > ?

With caps lock:
` 1 2 3 4 5 6 7 8 9 0 - =
   Q W E R T Y U I O P [ ]
    A S D F G H J K L ; ' #
   \ Z X C V B N M , . /

Example input / output

(The CapsLock line is just there for your understanding, and should not be outputted in your program)

Input:    abc ** def ! (ghijkl) mnop
Output:   abc 88 DEF 1 9GHIJKL0 mnop
CapsLock:     *      * *      *       (* means Caps Lock was pressed before this character)

Input:    print("Hello, World!"); sys.exit()
Output:   print92HELLO, world120; SYS.EXIT90
CapsLock:      *        *    *            *

Input:    !ABC!abc!ABC!abc!x!y!z
Output:   1ABC1ABC1abc1abc1X1y1Z
CapsLock: *       *       * * *

monopole

Posted 2014-10-14T17:22:48.030

Reputation: 1 559

You did the keyboards all wrong ;) http://meta.stackexchange.com/a/156177/314301

– J Atkin – 2016-02-21T03:23:32.513

3I would say that the opposite of this task would be more interesting :) (i.e to correct his wrongly types mails) – Optimizer – 2014-10-14T17:26:56.973

4@Optimizer Too ambiguous. Input HELLO could be "corrected" to Hello, HEllo, HELlo, etc. – Geobits – 2014-10-14T17:46:12.313

But the correct would be Hello only, as defined by word case (or fixed rules of correct English casing) – Optimizer – 2014-10-14T17:54:40.110

@Optimizer Sure, just pointing out it would need some strict rules, especially regarding numbers/symbols, which could be way more ambiguous than standard prose text. I agree it would be fun if done right. – Geobits – 2014-10-14T18:19:31.383

@Geobits Perhaps that could be a bonus (e.g. 50% bytes)? – monopole – 2014-10-14T19:50:13.067

4@laurencevs Honestly I'd rather see it as a separate challenge :) – Geobits – 2014-10-14T19:51:12.713

1What kind of voodoo keyboard is this? – Brandon – 2014-10-17T17:44:30.790

Answers

5

Python 2 - 269 275 290 318 337

Input is mostly safe if you use triple-quotes:"""print("Hello, World!"); sys.exit()"""

C=D=0
r=''
l,u,c=" `1234567890-=qwertyuiop[]asdfghjkl;'#\\zxcvbnm,./",' \xac!"\xa3$%^&*()_+QWERTYUIOP{}ASDFGHJKL:@~|ZXCVBNM<>?'," `1234567890-=QWERTYUIOP[]ASDFGHJKL;'#\\ZXCVBNM,./"
for h in input():w=h!=' ';U=h in u;C^=w&U&~D;D=U&w;r+=[l,c][C][[l,u][U].find(h)]
print r

Encoding doesn't seem to help much, except with the awkward ¬ and £ characters (I've tried looking at other problems like this and I think I should try to use split?)(It doesn't seem like the keyboard compresses enough to make it worth .decode, etc...)

Also, spaces suck.

Edit note: Indexing is weird

FryAmTheEggman

Posted 2014-10-14T17:22:48.030

Reputation: 16 206

3

PowerShell - 295

Takes input from the console (Read-Host), and outputs to the console.

$d=@("``1234567890-=qwertyuiop[]asdfghjkl;'#\zxcvbnm,./ ","``1234567890-=QWERTYUIOP[]ASDFGHJKL;'#\ZXCVBNM,./ ",'¬!"£$%^&*()_+QWERTYUIOP{}ASDFGHJKL:@~|ZXCVBNM<>? ')
((Read-Host).ToCharArray()|%{if($_-eq' '-or$d[2].IndexOf($_)-lt0){$a=0}else{if(!$a){$b=!$b}$a=2}$d[$b][$d[$a].IndexOf($_)]})-join''

puckipedia

Posted 2014-10-14T17:22:48.030

Reputation: 199