Which Row is the Key On?
JavaScript (ES6), 105 102 101 bytes

c=&gt;/[~`0-9!@#-&amp;^(-+_=-]/.test(c)+/[asdfghjkl;:'"\n]/i.test(c)*3+/[zxcvbnm,&lt;.&gt;/?]/i.test(c)*4||++c*7^2


Explanation

In JavaScript test returns a boolean which acts the same as 1 or 0 so I multiply them by their row. Testing for row 2 took the most bytes so I used that one as the default if no others matched.

c=&gt;
  /[~`0-9!@#-&amp;^(-+_=-]/.test(c)   // row 1 regex
  +/[asdfghjkl;:'"\n]/i.test(c)*3 // row 3 regex
  +/[zxcvbnm,&lt;.&gt;/?]/i.test(c)*4   // row 4 regex
  ||++c                           // space ++ = 1, any character on row 2 ++ = NaN
    *7^2                          // 7 XOR 2 = 5, NaN XOR 2 = 2


Test



var solution = c=&gt;/[~`0-9!@#-&amp;^(-+_=-]/.test(c)+/[asdfghjkl;:'"\n]/i.test(c)*3+/[zxcvbnm,&lt;.&gt;/?]/i.test(c)*4||++c*7^2
&lt;textarea id="input"&gt;-&lt;/textarea&gt;&lt;br /&gt;
&lt;button onclick="result.textContent=solution(input.value)"&gt;Go&lt;/button&gt;
&lt;pre id="result"&gt;&lt;/pre&gt;