[Question]
  [
# Code Golf Challenge
I have an isdue, my fingrrs are fat and I freqintly jave an isdue of ty[ing one keystrpke to the right on my kryboard.
I'm afraid the isdue is getyng worse anf worsr as time goes on.
Sopn every keystrpke I make wil; be shiftrd pne to the right!
Befpre then I'd like a program (or functipn) to autp shift every keystrpke back to the left one.
I'll make sure to take my tome typong the rest of tjis chal;enge so as not to cause anu confudion!
---
# Objective:
Write a program or function that takes an input of one of the following green keys on a standard QWERTY keyboard and returns the character of the key one to the left of it.[![enter image description here](https://i.stack.imgur.com/x4ImR.jpg)](https://i.stack.imgur.com/x4ImR.jpg)
---
# Conditions:
•You may assume that the person running this program is using a QWERTY keyboard like the one pictured above.
•Input and Output are both case-insensitive, you may use any case (or a mixture of case combinations) for this challenge and you can also assume all input will be in one case if desired.
•If your language has no way of allowing a user to input the return key for some reason you may ignore that one keystroke for this
•This challenge is just for the default values of the keys, for example if the `4` key is pressed you can assume it will always be `4` and never `$`
•You can assume only the green keys will ever be pressed.
---
# Example `Input` -> `Output`:
`S` -> `a`  
`4` -> `3`  
`=` -> `-`  
`[` -> `p`  
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the program with the shortest bytecount wins!
  
[Answer]
## Ruby, ~~76 71~~ 69 bytes
```
->a{"`1234567890-=qwertyuiop[]\\asdfghjkl;'\nzxcvbnm,./"[/.#{a}/][0]}
```
[Answer]
# [Perl 6](https://perl6.org), ~~87~~ ~~83~~ 69 bytes
```
{[Q"`1234567890-=qwertyuiop[]\asdfghjkl;'
zxcvbnm,./".comb].&{%(.[1..*]Z=>$_)}{$_}}
```
```
{~Q"`1234567890-=qwertyuiop[]\asdfghjkl;'
zxcvbnm,./".match(/.)>$_/)}
```
[Try it online!](https://tio.run/nexus/perl6#y61UUEtTsP1fXReolGBoZGxiamZuYWmga1tYnlpUUlmamV8QHRuTWJySlp6RlZ1jrc5VVZFclpSXq6Onr6SXm1iSnKGhr6dppxKvr1n7vzixUiFNQalYyZoLyjRBMG0RzGgl6/8A "Perl 6 – TIO Nexus")
Wondering if there's a way to encode that hard-coded string to something shorter...
*(Stole [G B's regex idea](https://codegolf.stackexchange.com/a/111135/14880) for -14 bytes.)*
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~34~~ 33 bytes
```
ØD”`1¦ṭØqż“[]\“;'¶“,./“0-=”Fṡ2UZy
```
[Try it online!](https://tio.run/nexus/jelly#@394hsujhrkJhoeWPdy59vCMwqN7HjXMiY6NAZLW6oe2ASkdPX0gaaBrC1Tn9nDnQqPQqMr/QJFiE9tooNDh9v8A "Jelly – TIO Nexus")
### How it works
```
ØD”`1¦ṭØqż“[]\“;'¶“,./“0-=”Fṡ2UZy  Main link. Argument: s (string)
ØD                                 Digits; yield "0123456789".
  ”`1|                             Replace '0' with a backtick.
       Øq                          Qwerty; yield
                                   ["qwertyuiop", "asdfghjkl", "zxcvbnm"].
      ṭ                            Tack; add "`123456789" as the last element of
                                   the qwerty array.
          “[]\“;'¶“,./“0-=”        Yield ["[]\\", ";'\n", "0-="].
         ż                         Zip; combine the strings of the array to the
                                   left with the corresponding strings of the array
                                   to the right, yielding an array of string pairs.
                           F       Flatten, yielding a string.
                            ṡ2     Obtain all overlapping pairs of characters.
                              U    Upend; reverse each pair.
                               Z   Zip, yielding a pair of strings.
                                y  Translate the input s according to the generated
                                   replacement table.
```
[Answer]
# Python 3, ~~85~~ 78 bytes:
```
lambda x,k="`1234567890-=qwertyuiop[]\\asdfghjkl;'\nzxcvbnm<>?":k[k.‌​find(x)-1]
```
[Answer]
# [Python](https://docs.python.org/2/), 76 bytes
```
s="1234567890-=qwertyuiop[]\\asdfghjkl;'\nzxcvbnm<>?"
dict(zip(s,'`'+s)).get
```
[Try it online!](https://tio.run/nexus/python2#NctZE4FAAADgZ37Fzr5UyCQ5ihj3fd9as5Ikamu2cvz6PPneP0tFsaO7l6sOAiXIhlQngaOHJguZCkyJYhpiAWP5nBPzUqFYKuPxhK/WMELb/WrX7vY2/eFo2hzM1E5jeWgtjmtE5icNYwxTEhffPAoMYBMA/18WePVt0vAb2Z6vnRAKrjfr/ng6FQaRj/G6ELdaq8Ns5PsmZTklmfCpTUJgZIDFGlz8Aw "Python 2 – TIO Nexus")
Makes a dictionary that takes each key to the one to its left by zipping the character string with its shifted version. The bottom line is the function, the top one is a definition.
Using `translate` to create a mapping gave a longer solution. [Try it online!](https://tio.run/nexus/python2#NctZE4FAAADgZ37Fzr5UyCQ5ihj3fd9as5Ikamu2cvz6PPneP0tFsaO7l6sOAiXIhlQngaOHJguZCkyJYhpiAWP5nBPzUqFYKuPxhK/WMELb/WrX7vY2/eFo2hzM1E5jeWgtjmtE5icNYwxTEhffPAoMYBMA/18WePVt0vAb2Z6vnRAKrjfr/ng6FQaRj/G6ELdaq8Ns5PsmZTklmfCpTUJgZIDFGlz8Aw "Python 2 – TIO Nexus")
```
lambda s:s.translate("';"*22+"_0__9`12345678_LM-<>_\\VXSWDFGUHJKNBIO=EARYCQZT\nP][___"*4)
```
[Answer]
# [Retina](https://github.com/m-ender/retina), 53 51 bytes
```
T`1-90\-=QW\ERTYUI\OP[]\\ASDF-HJ-L;'¶ZXCVBNM,./`\`o
```
[Try it online!](https://tio.run/nexus/retina#@x@SYKhraRCjaxsYHuMaFBIZ6hnjHxAdGxPjGOzipuvhpetjrX5oW1SEc5iTn6@Onn5CTEL@//@GRsYmpmbmFpYGurbhEG1gXUA97h5e3kA9XHAdAA "Retina – TIO Nexus")
A simple transliteration shifting every character 1 position backwards. Everything from `1` to `/` is the original character set, while the following part is the new set, using `o` to indicate the Other set.
`H` and `L` are special character classes for transliteration in retina (respectively mapping to Hex digits and uppercase Letters), but fortunately they occur on the keyboard inside alfabetically ordered sequences (`FGH` and `JKL`), so we can avoid escaping them by putting them in ranges and gain like that 2 bytes.
[Answer]
# C++, 109 bytes
```
void f(char i){std::string k="`1234567890-=qwertyuiop[]\\asdfghjkl;'\nzxcvbnm,./";std::cout<<k[k.find(i)-1];}
```
[Try it online!](https://tio.run/nexus/cpp-gcc#HcxJDoIwGEDhfU/R4IKSCIqzFLwIkFhbCr@FVpkcCGdH4tt@yZsWoHnZiQyHYJq2zlh1Qag3ILAkvGA1BmdoWhEEM4LOsYqsq7/Z7vaH4@m8dqPnK6vbTwfmEadJwhoh8@KuSmon@vvm/U1XS29l0f@Cm64NQxUrT4IWBBzXT@mIUMVAEwcNCM9JYhe2Q9E4TT8)
[Answer]
# TI-Basic, 70 bytes
I doubt that it could get any shorter than this...
```
Input Str1
"`1234567890-=QWERTYUIOP[]\ASDFGHJKL;'ZXCVBNM,./
sub(Ans,inString(Ans,Str1)-1,1
```
P.S. The two-byte tokens are `Str1`, ```, `\`, `sub(`, and `inString(`.
[Answer]
# [V](https://github.com/DJMcMayhem/V), ~~57~~ ~~54~~ 51 bytes
*3 bytes saved thanks to @nmjcman101 for using `hxVp` instead of what I had for the multiline keyboard*
```
i`¬190-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./<esc>/<C-r>a
hxVp
```
[Try it online!](https://tio.run/nexus/v#@5@ZcGiNoaWBrm1heWpRSWVpZn5BdGxMYnFKWnpGVnaOtXpVRXJZUl6ujp6@tL5QIldGRVjB////owE "V – TIO Nexus")
`<esc>` is `0x1b` and `<c-r>` is `0x12`
Note: this doesn't not support the enter key
Contains unprintables, so here's the hexdump
```
00000000: 6960 ac31 3930 2d3d 7177 6572 7479 7569  i`.190-=qwertyui
00000010: 6f70 5b5d 5c61 7364 6667 686a 6b6c 3b27  op[]\asdfghjkl;'
00000020: 7a78 6376 626e 6d2c 2e2f 1b2f 1261 0a68  zxcvbnm,././.a.h
00000030: 7856 70                                  xVp
```
### Explanation
Most of the program generates the keyboard. `i` enters insert mode and every character following it is printed to the buffer. But there is a small quirk here, `¬19` inserts characters between 1 and 9.
The program exits insert mode at the `<esc>`. And then here `/<c-r>a` it searches for the argument in the buffer. This brings the cursor on top of the character it found.
```
h                  " move the cursor to the left
 x                 " delete this character
  Vp               " select this line and replace it with the deleted character
```
[Answer]
# PowerShell, 82 bytes
```
$k="1234567890-=qwertyuiop[]\asdfghjkl;'
zxcvbnm,./";$k[$k.IndexOf((read-host))-1]
```
The Enter key is supported, but cannot be tested with `Read-Host` because the act of hitting enter with no value returns nothing in PowerShell.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 56 42 bytes
```
;D=Dv ·q i"[]\\",A i";'",22 +",./")Dg1nDbU
```
### Explanation
```
;D=Dv ·q i"[]\\",A i";'",22 +",./")Dg1nDbU
;D=D                                        // Shortcut for QWERTY (with newlines and spaces), assigning to variable D
    v                                       // Setting D to lowercase
      ·q                                    // Joining D into an array with no spaces or newlines
        i"[]\\",A                          // Inserting "[]\" into index 10 (A)
                   i";'",22                 // Inserting ";'" into index 22
                           +",./"           // Appending ",./"
                                  Dg        // Returns the character at index:
                                    1n      //    -1+
                                       DbU  //     Index of U (the input)
```
[Try it online!](https://tio.run/nexus/japt#@2/tYutSpnBoe6FCplJ0bEyMko6hAZBpra6kY2SkoK2ko6evpOmSbpjnkhT6/79StBIA "Japt – TIO Nexus")
[Answer]
# Java 8, 99 bytes
```
c->{String r="`1234567890-=qwertyuiop[]\\asdfghjkl;'\nzxcvbnm,./";return r.charAt(r.indexOf(c)-1);}
```
**Explanation:**
[Try it here.](https://tio.run/##hY/BbsIwDEDvfIXFpYm0ZmNjGyjqpH3A2IFji0RIU0hp3S5JOxjqt3dh5TpVsmXZftKzc9GKsKoV5umxl4WwFj6ExssEQKNTJhNSweraAsiDMCDJUCj3s86nD@uE0xJWgBBBL8O3y9oZjXsw0XQ7e3yaP7@8LpYPYfT1rYw7N7qq402SCJtm@0N@LHiQ4M9Jtjss79j9lBvlGoNg2FX17ohhGlN1@syIpOGM8q7ng7hudoUX3/xtpVMo/fVk0McbEHQ4fX22TpWsahyr/coVSJBJEtiA/j3yPzEfJaJRIh4lErwh3aTrfwE)
```
c->{                // Method with character as both parameter and return-type
  String r="`1234567890-=qwertyuiop[]\\asdfghjkl;'\nzxcvbnm,./";
                    //  Literal String of the qwerty keyboard layout of the challenge
  return r.charAt(  //  Return the character at the following index:
    r.indexOf(c)    //   The index of the input character
    -1);            //   -1 to shift it to the left
}                   // End of method
```
[Answer]
## JavaScript (ES6), 74 bytes
```
c=>(s=".,mnbvcxz\n';lkjhgfdsa\\][poiuytrewq=-0987654321`")[s.indexOf(c)+1]
```
Since `/` isn't in my string, `indexOf` returns `-1`, which when incremented causes `.` to be output. 93 bytes to process a string:
```
s=>s.replace(/./g,c=>s[s.indexOf(c)+1],s="><mnbvcxz\n';lkjhgfdsa\\][poiuytrewq=-0987654321`")
```
[Answer]
## [GNU sed](https://en.wikipedia.org/wiki/Sed), 72 + 1(r flag) = 73 bytes
```
s:$:`1234567890-=qwertyuiop[]\\asdfghjkl;'\nzxcvbnm,./:
s:(.).*(.)\1.*:\2:
```
The return key can't be tested, because sed by design splits the input using `\n` as the delimiter and then runs the script as many times as there are lines.
**Test run:** continuous input-output pair (when done press Ctrl + D or Ctrl + C)
```
me@LCARS:/PPCG$ sed -rf shift_key.sed
s
a
4
3
=
-
a
\
1
`
\
]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 50 bytes
```
'`žhÀ"-=qwertyuiop[]\\asdfghjkl;'\nzxcvbnm,./"JDÀ‡
```
[Try it online!](https://tio.run/nexus/05ab1e#@6@ecHRfxuEGJV3bwvLUopLK0sz8gujYmJjE4pS09Iys7Bxr9Zi8qorksqS8XB09fSUvl8MNjxoW/v@fkZqTk69Qnl@UkwIA "05AB1E – TIO Nexus")
Explanation:
```
'`                                                  # 1 char string: `
  žh                                                # Push numbers 0123456789
    À                                               # Rotated 1 left (123456890)
     "-=qwertyuiop[]\\asdfghjkl;'\nzxcvbnm,./"      # Push string literal
                                              J     # Join all elements pushed to the stack to one string
                                               D    # Duplicate
                                                À   # Rotate 1 left
                                                 ‡  # Transliterate: a.get(b.indexOf(input))
```
[Answer]
# Pyth - 56 bytes
```
@K"`1234567890-=qwertyuiop[]\\asdfghjkl;'
zxcvbnm,./"txK
```
[Test Suite](http://pyth.herokuapp.com/?code=%40K%22%601234567890-%3Dqwertyuiop%5B%5D%5C%5Casdfghjkl%3B%27%0Azxcvbnm%2C.%2F%22txK&test_suite=1&test_suite_input=%22s%22%0A%224%22%0A%22%3D%22%0A%22%5B%22&debug=0).
]