11
\$\begingroup\$

Here's an interesting challenge...

I want you to golf code that when executed will allow your input to be converted to mimic output as though you were typing on a DVORAK keyboard layout.

The aim is to mimic the US Simplified Dvorak Keyboard (US:SDK)

enter image description here

In comparison, here is the standard US QWERTY layout:

enter image description here

The keyboard emulation must work for both uppercase and lower case letters as well as shifted keys, for example, if I tapped the q (unshifted) key on my keyboard, the Dvorak code should pop out a ' character on the screen. If I were to tap the c (unshifted) button I should get a j (also unshifted) in response, C (shifted) would get J (shifted) and so on...

I am only concentrating of course on the white keys in the diagram above. Tabs, Caps and the other grey keys should work as per normal...

Any questions? Not for now? Good...

I will not allow external resources that already have the layout encoded already, I will not have any files brought in that can encode the layout. The code MUST be QWERTY INPUT -> (DVORAK RE-CODING) -> DVORAK OUTPUT in nature. No silly Esolangs that are theoretical or just say something like "This program will take QWERTY input and recode it in DVORAK. This is the program." or crap like that... Take this challenge seriously... So Brainfuck coders, I welcome you.

Please note, this is NOT a string conversion program. For every QWERTY key you press, the corresponding DVORAK character must be outputted...

Shortest code wins...

\$\endgroup\$
11
  • 1
    \$\begingroup\$ I think you need to specify a standard QWERTY layout if you want this to be a fair challenge. I suggest using this one. \$\endgroup\$
    – r3mainer
    Commented Mar 3, 2014 at 12:09
  • 8
    \$\begingroup\$ @JanDvorak We are waiting for your solution ;) \$\endgroup\$
    – VisioN
    Commented Mar 3, 2014 at 12:29
  • 3
    \$\begingroup\$ I don't fully understand. If string manipulation is prohibited, does it mean that stdin is out of the question? So I have to implement some low-level keyboard IO that reads keypresses? This also disqualifies brainfuck, which only reads strings from the stdin. What about stdout, can I send strings to the stdout or do I need to code a keyboard driver of sorts which simulates pressing a different key? \$\endgroup\$
    – fejesjoco
    Commented Mar 3, 2014 at 13:03
  • 1
    \$\begingroup\$ @fejesjoco are you referring to the last sentence? I read that as "STDIN must be read from and STDOUT written to without buffering" \$\endgroup\$ Commented Mar 3, 2014 at 13:41
  • 2
    \$\begingroup\$ As an aside, your questions seem to always generate a large discussion in the comment thread. Maybe it is a sign you should be using the sandbox more? \$\endgroup\$ Commented Mar 3, 2014 at 14:51

6 Answers 6

8
\$\begingroup\$

C - 144 characters

main(c){putch((c=getch())>33?c:"_#$%&-()*}w[vz0123456789SsW]VZ@AXJE>UIDCHTNMBRL\"POYGK<QF:/\\
=^{`axje.uidchtnmbrl'poygk,qf?|+~"[c-34]);main(0);}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Nice solution ;-) \$\endgroup\$
    – mirabilos
    Commented Mar 3, 2014 at 15:35
7
\$\begingroup\$

Shell: Unix tr(1), 94

tr \''"+-/:-[]_b-{}' "-_}w[vzSsW]VZ@AXJE>UIDCHTNMBRL\"POYGK<QF:/={xje.uidchtnmbrl'poygk,qf;?+"

This command takes QWERTY on stdin and outputs DVORAK on stdout.

\$\endgroup\$
2
  • \$\begingroup\$ Darn, you beat me to it! \$\endgroup\$
    – TheDoctor
    Commented Mar 3, 2014 at 15:34
  • \$\begingroup\$ @TheDoctor I just happened on this question early enough ☻ took me a while (about 20 minutes?) to optimise e.g. the ranges, though. \$\endgroup\$
    – mirabilos
    Commented Mar 3, 2014 at 15:35
4
\$\begingroup\$

C#, 360 characters

Probably not the shortest, but it does exactly what you ask:

using System;class A{static void Main(){string[] q={"-=qwertyuiop[]sdfghjkl;'zxcvbnm,./","_+QWERTYUIOP{}SDFGHJKL:\"ZXCVBNM<>?","[]',.pyfgcrl/=oeuidhtns-;qjkxbmwvz","{}\"<>PYFGCRL?+OEUIDHTNS_:QJKXBMWVZ"};while(true){var c=Console.ReadKey(true);var a=c.KeyChar;int i,w=c.Modifiers==ConsoleModifiers.Shift?1:0;Console.Write((i=q[w].IndexOf(a))>-1?q[w+2][i]:a);}}}

If you press a key on your QWERTY keyboard, then the correct DVORAK character appears in the console.

\$\endgroup\$
3
\$\begingroup\$

AutoHotKey, 200 bytes

-::[
=::]
q::'
w::,
e::.
r::p
t::y
y::f
u::g
i::c
o::r
p::l
[::/
]::=
s::o
d::e
f::u
g::i
h::d
j::h
k::t
l::n
`;::s
'::-
z::`;
x::q
c::j
v::k
b::x
n::b
,::w
.::v
/::z

There should be an answer in AHK for this question but not. So just post one.

\$\endgroup\$
3
  • \$\begingroup\$ Shouldn't there be a "return"? \$\endgroup\$
    – MilkyWay90
    Commented Dec 9, 2018 at 20:38
  • \$\begingroup\$ @MilkyWay90 OP didn't ask for halting. And this program will continue run until you manually exit it by clicking tray menu. So, no "return" involved. \$\endgroup\$
    – tsh
    Commented Dec 10, 2018 at 2:13
  • \$\begingroup\$ Oh okay thank you for the explanation. \$\endgroup\$
    – MilkyWay90
    Commented Dec 10, 2018 at 3:25
1
\$\begingroup\$

R, 157 bytes

Simple translate script.

chartr('\'qQwWeErRtTyYuUiIoOpP[{]}sSdDfFgGhHjJkKlL;:"zZxXcCvVbBnN,<.>/?=_+-','-\'",<.>pPyYfFgGcCrRlL/?=+oOeEuUiIdDhHtTnNsS_;:qQjJkKxXbBwWvVzZ{]}[',scan(,''))

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Python, 181 bytes

print(input().translate(str.maketrans("'qQwWeErRtTyYuUiIoOpP[{]}sSdDfFgGhHjJkKlL;:\"zZxXcCvVbBnN,<.>/?=_+-","-'\",<.>pPyYfFgGcCrRlL/?=+oOeEuUiIdDhHtTnNsS_;:qQjJkKxXbBwWvVzZ{]}[")))

This code takes QWERTY on stdin and outputs DVORAK on stdout.

It does this by creating a translation table from qwerty to dvorak then translates stdin with input() using that translation table

A cleaner representation

print(
    input().translate(
        str.maketrans(
            "'qQwWeErRtTyYuUiIoOpP[{]}sSdDfFgGhHjJkKlL;:\"zZxXcCvVbBnN,<.>/?=_+-",
            "-'\",<.>pPyYfFgGcCrRlL/?=+oOeEuUiIdDhHtTnNsS_;:qQjJkKxXbBwWvVzZ{]}[",
        )
    )
)

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.