7
\$\begingroup\$

Here's an interesting challenge...

I want you to golf code than 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\$
  • 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\$ – squeamish ossifrage Mar 3 '14 at 12:09
  • 6
    \$\begingroup\$ @JanDvorak We are waiting for your solution ;) \$\endgroup\$ – VisioN Mar 3 '14 at 12:29
  • 2
    \$\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 Mar 3 '14 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\$ – John Dvorak Mar 3 '14 at 13:41
  • 1
    \$\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\$ – Tim Seguine Mar 3 '14 at 14:51
6
\$\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\$
  • \$\begingroup\$ Darn, you beat me to it! \$\endgroup\$ – TheDoctor Mar 3 '14 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 Mar 3 '14 at 15:35
7
\$\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\$
  • \$\begingroup\$ Nice solution ;-) \$\endgroup\$ – mirabilos Mar 3 '14 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\$
2
\$\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\$
  • \$\begingroup\$ Shouldn't there be a "return"? \$\endgroup\$ – MilkyWay90 Dec 9 '18 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 Dec 10 '18 at 2:13
  • \$\begingroup\$ Oh okay thank you for the explanation. \$\endgroup\$ – MilkyWay90 Dec 10 '18 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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