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...
6 Answers 6
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);}
-
1\$\begingroup\$ Nice solution ;-) \$\endgroup\$mirabilos– mirabilos2014年03月03日 15:35:12 +00:00Commented Mar 3, 2014 at 15:35
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.
-
\$\begingroup\$ Darn, you beat me to it! \$\endgroup\$TheDoctor– TheDoctor2014年03月03日 15:34:30 +00:00Commented 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– mirabilos2014年03月03日 15:35:54 +00:00Commented Mar 3, 2014 at 15:35
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.
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.
-
\$\begingroup\$ Shouldn't there be a "return"? \$\endgroup\$MilkyWay90– MilkyWay902018年12月09日 20:38:13 +00:00Commented 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– tsh2018年12月10日 02:13:51 +00:00Commented Dec 10, 2018 at 2:13
-
\$\begingroup\$ Oh okay thank you for the explanation. \$\endgroup\$MilkyWay90– MilkyWay902018年12月10日 03:25:17 +00:00Commented Dec 10, 2018 at 3:25
R, 157 bytes
Simple translate script.
chartr('\'qQwWeErRtTyYuUiIoOpP[{]}sSdDfFgGhHjJkKlL;:"zZxXcCvVbBnN,<.>/?=_+-','-\'",<.>pPyYfFgGcCrRlL/?=+oOeEuUiIdDhHtTnNsS_;:qQjJkKxXbBwWvVzZ{]}[',scan(,''))
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{]}[",
)
)
)
;)\$\endgroup\$