DVORAK Keyboard layout

8

1

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...

WallyWest

Posted 2014-03-03T11:43:08.590

Reputation: 6 949

1

I think you need to specify a standard QWERTY layout if you want this to be a fair challenge. I suggest using this one.

– r3mainer – 2014-03-03T12:09:01.267

Point taken, implemented... – WallyWest – 2014-03-03T12:10:55.870

Is it really necessary to pop a DVORAK character when I type a QWERTY character, or is it also OK to accept a QWERTY string as input and convert it to a DVORAK string? – ProgramFOX – 2014-03-03T12:28:33.783

6@JanDvorak We are waiting for your solution ;) – VisioN – 2014-03-03T12:29:49.640

It is ESSENTIAL that the respective key on the QWERTY keyboard generates the respective DVORAK response... This is NOT string manipulation... This is Key-for-Key conversion. – WallyWest – 2014-03-03T12:30:45.920

2I 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? – fejesjoco – 2014-03-03T13:03:16.020

1@fejesjoco are you referring to the last sentence? I read that as "STDIN must be read from and STDOUT written to without buffering" – John Dvorak – 2014-03-03T13:41:41.580

You can read a string from stdin and write it to stdout with buffering. You can do the same unbuffered, with characters (getchar/putchar in C), or do both for different directions. But it's essentially the same thing, it won't yield very different programs. So I don't understand why this distinction is necessary. Reading key events (where you get a scancode, not a character) is something else, which would fit the question, but it's too lowlevel, and changing key events is essentially device driver stuff... – fejesjoco – 2014-03-03T13:47:10.067

Should backspace delete a character from stdout? I think that would be the only sensible way to interpret the "this is not string manipulation" bit. – Tim Seguine – 2014-03-03T14:48:29.230

1As 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? – Tim Seguine – 2014-03-03T14:51:04.553

@TimSeguine Quite possibly, but all I was expecting was code that took STDIN and produced the DVORAK equivalent to STDOUT... Sighs

At least Jan Dvorak has read that perfectly... – WallyWest – 2014-03-03T23:23:45.547

Answers

7

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.

mirabilos

Posted 2014-03-03T11:43:08.590

Reputation: 422

Darn, you beat me to it! – TheDoctor – 2014-03-03T15:34:30.473

@TheDoctor I just happened on this question early enough ☻ took me a while (about 20 minutes?) to optimise e.g. the ranges, though. – mirabilos – 2014-03-03T15:35:54.573

8

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);}

Oberon

Posted 2014-03-03T11:43:08.590

Reputation: 2 881

1Nice solution ;-) – mirabilos – 2014-03-03T15:35:12.697

4

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.

ProgramFOX

Posted 2014-03-03T11:43:08.590

Reputation: 8 017

3

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.

tsh

Posted 2014-03-03T11:43:08.590

Reputation: 13 072

Shouldn't there be a "return"? – MilkyWay90 – 2018-12-09T20:38:13.697

@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. – tsh – 2018-12-10T02:13:51.087

Oh okay thank you for the explanation. – MilkyWay90 – 2018-12-10T03:25:17.330

1

R, 157 bytes

Simple translate script.

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

Try it online!

CT Hall

Posted 2014-03-03T11:43:08.590

Reputation: 591